Skip to content

Commit ef61555

Browse files
committed
Use an in-house reusable workflow
1 parent 3089952 commit ef61555

File tree

3 files changed

+3
-359
lines changed

3 files changed

+3
-359
lines changed

.github/workflows/releaser.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/rust.yml

Lines changed: 3 additions & 246 deletions
Original file line numberDiff line numberDiff line change
@@ -7,251 +7,8 @@ on:
77
- main
88
paths-ignore:
99
- '.github/**'
10-
- "Cargo.toml"
11-
12-
env:
13-
CARGO_TERM_COLOR: always
1410

1511
jobs:
16-
release:
17-
runs-on: thevickypedia-lite
18-
permissions:
19-
contents: write
20-
outputs:
21-
release-id: ${{ steps.create-release.outputs.release_id }}
22-
release-tag: ${{ steps.create-release.outputs.release_tag }}
23-
release-flag: ${{ steps.set-release-flag.outputs.release_flag }}
24-
pkg-name: ${{ steps.get-package-info.outputs.pkg_name }}
25-
bin-name: ${{ steps.get-package-info.outputs.bin_name }}
26-
steps:
27-
- uses: actions/checkout@v4
28-
- name: Get Package Name
29-
id: get-package-info
30-
run: |
31-
pkg_name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
32-
echo "Package Name: $pkg_name"
33-
echo "pkg_name=$pkg_name" >> $GITHUB_ENV
34-
echo "pkg_name=$pkg_name" >> "$GITHUB_OUTPUT"
35-
36-
bin_name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].targets[] | select(.kind[] == "bin" or .crate_types[] == "bin") | .name')
37-
echo "Bin Name: $bin_name"
38-
echo "bin_name=$bin_name" >> $GITHUB_ENV
39-
echo "bin_name=$bin_name" >> "$GITHUB_OUTPUT"
40-
shell: bash
41-
- name: Set Release Flag # Release flag is set only for a push on main branch
42-
id: set-release-flag
43-
run: |
44-
current_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
45-
# latest_version=$(curl -s https://crates.io/api/v1/crates/${{ env.pkg_name }} | jq -r '.versions[0].num')
46-
versions=$(curl -s https://crates.io/api/v1/crates/${{ env.pkg_name }} | jq -r '.versions | map(.num)')
47-
latest_version=$(echo $versions | jq -r '.[0]')
48-
echo "Current Package Version: ${current_version}"
49-
echo "Latest Package Version: $latest_version"
50-
version_exists=false
51-
for version in $(echo "$versions" | jq -r '.[]'); do
52-
trimmed=$(echo "$version" | awk '{$1=$1};1')
53-
if [ "$trimmed" == "$current_version" ]; then
54-
version_exists=true
55-
break
56-
fi
57-
done
58-
if [ "$version_exists" = true ]; then
59-
echo "Version $current_version exists in crates.io, setting release flag to 'false'"
60-
echo "release=false" >> $GITHUB_ENV
61-
echo "release_flag=false" >> "$GITHUB_OUTPUT"
62-
else
63-
echo "Version $current_version does not exist in crates.io, setting release flag to 'true'"
64-
echo "release=true" >> $GITHUB_ENV
65-
echo "release_flag=true" >> "$GITHUB_OUTPUT"
66-
fi
67-
echo "pkg_version=$current_version" >> $GITHUB_ENV
68-
shell: bash
69-
- name: Create New Release
70-
if: env.release == 'true'
71-
id: create-release
72-
run: |
73-
release_tag="v${{ env.pkg_version }}"
74-
echo "release_tag=${release_tag}" >> "$GITHUB_OUTPUT"
75-
cargo_prerelease=("alpha" "beta" "rc")
76-
prerelease=false
77-
for cargo_pre in "${cargo_prerelease[@]}"; do
78-
if [[ $pkg_version == *"$cargo_pre"* ]]; then
79-
prerelease=true
80-
break
81-
fi
82-
done
83-
84-
echo "Release Tag: $release_tag"
85-
latest_tag=$(curl -s -L https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
86-
commit_msg="$(git log -1 --pretty=%B | sed ':a;N;$!ba;s/\n/\\n/g')"
87-
commit_msg+="\n**Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/$latest_tag...$release_tag"
88-
release_data="{\"tag_name\":\"$release_tag\",\"name\":\"$release_tag\",\"body\":\"$commit_msg\",\"draft\":false,\"prerelease\":$prerelease}"
89-
response=$(curl -X POST -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \
90-
-d "$release_data" \
91-
"https://api.github.com/repos/${{ github.repository }}/releases")
92-
93-
echo "Response: $response"
94-
release_id=$(echo $response | jq -r .id)
95-
if [ "$release_id" = "null" ] || [ -z "$release_id" ]; then
96-
echo "Error: release_id is null. Exiting with code 1."
97-
exit 1
98-
fi
99-
echo "Release ID: $release_id"
100-
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
101-
shell: bash
102-
103-
upload_assets:
104-
needs: release
105-
strategy:
106-
matrix:
107-
platform:
108-
- release_for: Linux-x86_64
109-
os: linux-amd64
110-
bin: ${{ needs.release.outputs.bin-name }}
111-
name: ${{ needs.release.outputs.pkg-name }}-Linux-x86_64.tar.gz
112-
113-
- release_for: Windows-x86_64
114-
os: windows-amd64
115-
bin: ${{ needs.release.outputs.bin-name }}.exe
116-
name: ${{ needs.release.outputs.pkg-name }}-Windows-x86_64.zip
117-
118-
- release_for: macOS-x86_64
119-
os: darwin-amd64
120-
bin: ${{ needs.release.outputs.bin-name }}
121-
name: ${{ needs.release.outputs.pkg-name }}-Darwin-x86_64.tar.gz
122-
123-
- release_for: macOS-arm64
124-
os: darwin-arm64
125-
bin: ${{ needs.release.outputs.bin-name }}
126-
name: ${{ needs.release.outputs.pkg-name }}-Darwin-arm64.tar.gz
127-
128-
name: Upload asset for ${{ matrix.platform.release_for }}
129-
if: needs.release.outputs.release-flag == 'true'
130-
runs-on: ${{ matrix.platform.os }}
131-
permissions:
132-
contents: write
133-
134-
steps:
135-
- name: Release ID Propagation
136-
id: release-id-check
137-
run: |
138-
if [ -n "${{ needs.release.outputs.release-id }}" ]; then
139-
echo "Release ID propagated: ${{ needs.release.outputs.release-id }}"
140-
else
141-
echo "Release ID propagation failed. Exiting.."
142-
exit 1
143-
fi
144-
echo "start_time=$(date +%s)" >> "$GITHUB_ENV"
145-
shell: bash
146-
- name: Checkout Repo
147-
uses: actions/checkout@v4
148-
- name: Update Rust
149-
# print it with style
150-
run: |
151-
printf '*%.0s' {1..60} && printf "\n"
152-
echo "Existing rust version: $(rustc --version)"
153-
printf '*%.0s' {1..60} && printf "\n\n"
154-
rustup update && printf "\n"
155-
printf '*%.0s' {1..60} && printf "\n"
156-
echo "Updated rust version: $(rustc --version)"
157-
printf '*%.0s' {1..60} && printf "\n"
158-
shell: bash
159-
160-
- name: Install OpenSSL static for Windows
161-
# https://github.com/sfackler/rust-openssl/issues/1086
162-
if: startsWith(matrix.platform.os, 'windows')
163-
run: |
164-
if (-Not (Test-Path -Path \Tools)) {
165-
mkdir \Tools
166-
}
167-
cd \Tools
168-
if (-Not (Test-Path -Path .\vcpkg)) {
169-
git clone https://github.com/Microsoft/vcpkg.git
170-
}
171-
cd vcpkg
172-
echo ("vcpkg_dir=" + $pwd) >> $env:GITHUB_ENV
173-
if (-Not (Test-Path -Path .\vcpkg.exe)) {
174-
.\bootstrap-vcpkg.bat
175-
}
176-
.\vcpkg.exe install openssl:x64-windows-static
177-
shell: pwsh
178-
179-
- name: Build
180-
run: |
181-
if [[ "${{ matrix.platform.os }}" =~ ^windows ]]; then
182-
echo "Setting vcpkg env vars for OpenSSL in Windows"
183-
export OPENSSL_DIR="${{ env.vcpkg_dir }}\installed\x64-windows-static"
184-
export OPENSSL_STATIC="Yes"
185-
export VCPKG_ROOT="${{ env.vcpkg_dir }}\installed\x64-windows-static"
186-
fi
187-
cargo build --release
188-
shell: bash
189-
190-
- name: Run tests
191-
run: |
192-
if [[ "${{ matrix.platform.os }}" =~ ^windows ]]; then
193-
echo "Setting vcpkg env vars for OpenSSL in Windows"
194-
export OPENSSL_DIR="${{ env.vcpkg_dir }}\installed\x64-windows-static"
195-
export OPENSSL_STATIC="Yes"
196-
export VCPKG_ROOT="${{ env.vcpkg_dir }}\installed\x64-windows-static"
197-
fi
198-
cargo test --no-run
199-
shell: bash
200-
201-
- name: Compress and Copy Artifact (Windows)
202-
if: startsWith(matrix.platform.os, 'windows')
203-
run: |
204-
mkdir -p ${{ needs.release.outputs.pkg-name }}
205-
cp target/release/${{ matrix.platform.bin }} ${{ needs.release.outputs.pkg-name }}/${{ matrix.platform.bin }}
206-
Compress-Archive -DestinationPath ${{ matrix.platform.name }} -Path ${{ needs.release.outputs.pkg-name }}/
207-
shell: pwsh
208-
209-
- name: Compress and Copy Artifact (macOS/Ubuntu)
210-
if: "!startsWith(matrix.platform.os, 'windows')"
211-
run: |
212-
mkdir -p ${{ needs.release.outputs.pkg-name }}
213-
cp target/release/${{ matrix.platform.bin }} ${{ needs.release.outputs.pkg-name }}/${{ matrix.platform.bin }}
214-
tar -zcvf ${{ matrix.platform.name }} ${{ needs.release.outputs.pkg-name }}/
215-
shell: bash
216-
217-
- name: Upload Asset to Release
218-
run: |
219-
curl -X POST -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \
220-
-H "Content-Type: application/octet-stream" \
221-
--data-binary @"${{ matrix.platform.name }}" \
222-
"https://uploads.github.com/repos/${{ github.repository }}/releases/${{ needs.release.outputs.release-id }}/assets?name=${{ matrix.platform.name }}"
223-
shell: bash
224-
225-
- name: Runtime Analyzer
226-
run: |
227-
start=${{ env.start_time }}
228-
end=$(date +%s)
229-
time_taken=$((end-start))
230-
url="${{ github.server_url }}/${{ github.repository }}/releases/download/${{ needs.release.outputs.release-tag }}/${{ matrix.platform.name }}"
231-
hyperlink="[${{ matrix.platform.release_for }}]($url)"
232-
echo "🚀 Built for $hyperlink in $time_taken seconds" >> $GITHUB_STEP_SUMMARY
233-
shell: bash
234-
235-
publish-crate:
236-
needs:
237-
- release
238-
- upload_assets
239-
if: needs.release.outputs.release-flag == 'true'
240-
runs-on: thevickypedia-lite
241-
steps:
242-
- uses: actions/checkout@v4
243-
- name: Update Rust
244-
run: |
245-
printf '*%.0s' {1..60} && printf "\n"
246-
echo "Existing rust version: $(rustc --version)"
247-
printf '*%.0s' {1..60} && printf "\n\n"
248-
rustup update && printf "\n"
249-
printf '*%.0s' {1..60} && printf "\n"
250-
echo "Updated rust version: $(rustc --version)"
251-
printf '*%.0s' {1..60} && printf "\n"
252-
shell: bash
253-
- name: Release Crate
254-
run: |
255-
cargo login ${{ secrets.CRATES_TOKEN }}
256-
cargo publish --allow-dirty # Set allow-dirty since building will create a /target folder that will be uncommitted in git
257-
shell: bash
12+
iOS:
13+
uses: thevickypedia/rust-releaser/.github/workflows/entrypoint.yml@main
14+
secrets: inherit

.github/workflows/temp.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)