Skip to content

Commit b28da46

Browse files
committed
Add publish workflow
1 parent 9cb54f1 commit b28da46

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

.github/workflows/publish.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Check, build assets and publish project
2+
3+
on:
4+
push
5+
6+
jobs:
7+
check:
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
project: [current-issues]
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: dtolnay/rust-toolchain@stable
17+
18+
- name: Check
19+
run: cargo check
20+
working-directory: ${{ matrix.project }}
21+
22+
- name: Lint
23+
run: cargo clippy
24+
working-directory: ${{ matrix.project }}
25+
26+
publish-assets:
27+
needs: check
28+
29+
permissions: write-all
30+
31+
strategy:
32+
matrix:
33+
os: [ubuntu-latest, windows-latest, macos-latest]
34+
binary: [current-issues]
35+
include:
36+
- os: windows-latest
37+
platform-name: x86_64-pc-windows
38+
executable-extension: ".exe"
39+
- os: ubuntu-latest
40+
platform-name: x86_64-unknown-linux
41+
- os: macos-latest
42+
platform-name: aarch64-apple-darwin
43+
44+
runs-on: ${{ matrix.os }}
45+
46+
env:
47+
PROFILE: dev
48+
OUT: target/debug
49+
GH_RELEASE: assets
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: dtolnay/rust-toolchain@stable
54+
55+
- name: Set variables
56+
id: information
57+
shell: bash
58+
run: |
59+
echo "GITHUB_RUN_DATE=$(TZ="Europe/London" date +"%Y-%m-%d %T")" >> "$GITHUB_OUTPUT"
60+
echo "GIT_LAST_COMMIT=$(git log -n 1 --format="%H")" >> "$GITHUB_OUTPUT"
61+
IFS='~' read -r project example <<< '${{ matrix.binary }}'
62+
echo "WORKING_DIRECTORY=$project" >> "$GITHUB_OUTPUT"
63+
echo "PROJECT_NAME=$project" >> "$GITHUB_OUTPUT"
64+
if [ -n "$example" ]; then
65+
echo "BUILD_SPECIFIER=--example $example" >> "$GITHUB_OUTPUT"
66+
echo "ASSET_PATH=${{ env.OUT }}/examples/$example${{ matrix.executable-extension }}" >> "$GITHUB_OUTPUT"
67+
echo "ASSET_NAME=$example" >> "$GITHUB_OUTPUT"
68+
else
69+
echo "BUILD_SPECIFIER=" >> "$GITHUB_OUTPUT"
70+
echo "ASSET_PATH=${{ env.OUT }}/$project${{ matrix.executable-extension }}" >> "$GITHUB_OUTPUT"
71+
echo "ASSET_NAME=$project" >> "$GITHUB_OUTPUT"
72+
fi
73+
74+
- name: Build binary
75+
working-directory: ${{ steps.information.outputs.WORKING_DIRECTORY }}
76+
run: cargo build ${{ steps.information.outputs.BUILD_SPECIFIER }} --profile ${{ env.PROFILE }}
77+
env:
78+
GITHUB_RUN_DATE: ${{ steps.information.outputs.GITHUB_RUN_DATE }}
79+
GIT_LAST_COMMIT: ${{ steps.information.outputs.GIT_LAST_COMMIT }}
80+
81+
- name: Publish binary
82+
working-directory: ${{ steps.information.outputs.WORKING_DIRECTORY }}
83+
shell: bash
84+
env: { "GH_TOKEN": "${{ secrets.GITHUB_TOKEN }}" }
85+
run: |
86+
FROM='${{ steps.information.outputs.ASSET_PATH }}'
87+
TO='${{ steps.information.outputs.ASSET_NAME }}-${{ matrix.platform-name }}${{ matrix.executable-extension }}'
88+
LABEL="${{ steps.information.outputs.PROJECT_NAME }}-$TO"
89+
mv $FROM $TO
90+
gh release upload $GH_RELEASE "$TO#LABEL" --clobber
91+

0 commit comments

Comments
 (0)