1+ name : Rust CI/CD Pipeline
2+
3+ on :
4+ push :
5+ branches : [ "master" ]
6+ types : [ edited ]
7+
8+ pull_request :
9+ branches : [ "master" ]
10+ types : [ opened, synchronize ]
11+
12+ env :
13+ CARGO_TERM_COLOR : always
14+
15+ jobs :
16+ get-info :
17+ runs-on : ubuntu-latest
18+ outputs :
19+ cargo_version : ${{ steps.get-version.outputs.VERSION }}
20+ workflow_git_tag : ${{ steps.get-version.outputs.WORKFLOW_GIT_TAG }}
21+ steps :
22+ - uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0
25+ token : ${{ secrets.RELEASE_TOKEN }}
26+
27+ - name : Get Version from Cargo.toml
28+ id : get-version
29+ run : |
30+ VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
31+ echo "VERSION=$VERSION"
32+ echo "WORKFLOW_GIT_TAG=v$VERSION"
33+ echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
34+ echo "WORKFLOW_GIT_TAG=v$VERSION" >> "$GITHUB_OUTPUT"
35+ build :
36+ needs : get-info
37+ strategy :
38+ matrix :
39+ os : [ ubuntu-latest, macos-14, windows-latest ]
40+ runs-on : ${{ matrix.os }}
41+ steps :
42+ - name : Checkout
43+ uses : actions/checkout@v4
44+
45+ - name : Build
46+ run : cargo build --release --verbose
47+
48+ - name : Copy release binary to root
49+ shell : bash
50+ run : |
51+ pwd
52+ if [[ -f "target/release/singen" ]]; then
53+ cp -v target/release/singen .
54+ elif [[ -f "target/release/singen.exe" ]]; then
55+ cp -v target/release/singen .
56+ else
57+ echo "No binary to copy for this OS."
58+ fi
59+
60+ - name : Get Build Info
61+ id : build-info
62+ shell : bash
63+ run : |
64+ OS=$(uname -s | tr '[:upper:]' '[:lower:]')
65+ ARCH=$(uname -m)
66+ TARGET=""
67+ case "$OS" in
68+ linux) TARGET="$ARCH-unknown-linux-gnu" ;;
69+ darwin) TARGET="$ARCH-apple-darwin" ;;
70+ msys*|cygwin*|mingw*) TARGET="$ARCH-pc-windows-msvc" ;;
71+ esac
72+ VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
73+ FILENAME="singen-v${VERSION}-${TARGET}"
74+ echo "OS=$OS" >> "$GITHUB_ENV"
75+ echo "ARCH=$ARCH" >> "$GITHUB_ENV"
76+ echo "TARGET=$TARGET" >> "$GITHUB_ENV"
77+ echo "FILENAME=$FILENAME" >> "$GITHUB_ENV"
78+
79+ - name : Compress tar.gz
80+ uses : ksm2/archive-action@v1
81+ with :
82+ name : " ${{ env.FILENAME }}"
83+ format : " tar.gz"
84+ include : " {singen,singen.exe,README.md}"
85+
86+ - name : Compress zip
87+ uses : ksm2/archive-action@v1
88+ with :
89+ name : " ${{ env.FILENAME }}"
90+ format : " zip"
91+ include : " {singen,singen.exe,README.md,LICENSE}"
92+
93+ - name : Create or Update Release
94+ env :
95+ VERSION : ${{ needs.get-info.outputs.cargo_version }}
96+ WORKFLOW_GIT_TAG : ${{ needs.get-info.outputs.workflow_git_tag}}
97+ uses : ncipollo/release-action@v1
98+ with :
99+ artifacts : " ${{ env.FILENAME }}.tar.gz,${{ env.FILENAME }}.zip"
100+ allowUpdates : ' true'
101+ generateReleaseNotes : ' true'
102+ token : ${{ secrets.RELEASE_TOKEN }}
103+ tag : ${{ env.WORKFLOW_GIT_TAG }}
0 commit comments