1+ name : CD
2+
3+ on :
4+ release :
5+ types :
6+ - created # Trigger this workflow when a new release is created
7+
8+ jobs :
9+ # Build and release binaries for Linux and Windows
10+ linux_windows :
11+ runs-on : ubuntu-latest
12+ permissions :
13+ contents : write
14+ checks : write
15+
16+ actions : read
17+ issues : read
18+ packages : write
19+ pull-requests : read
20+ repository-projects : read
21+ statuses : read
22+ steps :
23+ - name : Checkout the repository
24+ uses : actions/checkout@v2 # Checkout the repository to the runner
25+
26+ - name : Install Linux and Windows Cross Compilers
27+ run : sudo apt-get install --yes --no-install-recommends musl-tools gcc-mingw-w64-x86-64-win32 # Install necessary cross-compilers for Linux and Windows
28+
29+ - name : Install rustup targets
30+ run : rustup target add x86_64-unknown-linux-musl x86_64-pc-windows-gnu
31+
32+ - name : Build the executable
33+ run : cargo build --release --target x86_64-unknown-linux-musl --target x86_64-pc-windows-gnu # Build the executable for both Linux and Windows targets
34+
35+ - name : Build release name
36+ run : |
37+ PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
38+ PKG_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
39+ RELEASE_NAME="${PKG_NAME}_${PKG_VERSION}"
40+ echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
41+
42+ - name : Tar x86_64 binary
43+ run : |
44+ PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
45+ tar -czvf ${{ env.RELEASE_NAME }}-gnu-linux-x86_64.tar.gz -C target/x86_64-unknown-linux-musl/release ${PKG_NAME}
46+
47+ - name : Zip windows binary
48+ run : |
49+ PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
50+ zip -j ${{ env.RELEASE_NAME }}-windows.zip target/x86_64-pc-windows-gnu/release/${PKG_NAME}.exe
51+
52+ - name : Generate SHA256 checksums
53+ run : |
54+ shasum -a 256 ${{ env.RELEASE_NAME }}-gnu-linux-x86_64.tar.gz > ${{ env.RELEASE_NAME }}-gnu-linux-x86_64.tar.gz.sha256
55+ shasum -a 256 ${{ env.RELEASE_NAME }}-windows.zip > ${{ env.RELEASE_NAME }}-windows.zip.sha256
56+
57+ - name : Upload release binaries
58+ uses : softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # Use the third party action to upload the release binaries
59+ env :
60+ GITHUB_TOKEN : ${{ github.token }} # Use the GitHub token for authentication
61+ with :
62+ files : |
63+ ${{ env.RELEASE_NAME }}-gnu-linux-x86_64.tar.gz
64+ ${{ env.RELEASE_NAME }}-windows.zip
65+ ${{ env.RELEASE_NAME }}-gnu-linux-x86_64.tar.gz.sha256
66+ ${{ env.RELEASE_NAME }}-windows.zip.sha256
67+
68+ # Build and release binaries for MacOS (x86_64 and arm64)
69+ macos :
70+ runs-on : macos-latest
71+ permissions :
72+ contents : write
73+ checks : write
74+
75+ actions : read
76+ issues : read
77+ packages : write
78+ pull-requests : read
79+ repository-projects : read
80+ statuses : read
81+ steps :
82+ - name : Checkout the repository
83+ uses : actions/checkout@v2
84+
85+ - name : Install rustup targets
86+ run : rustup target add x86_64-apple-darwin aarch64-apple-darwin
87+
88+ - name : Build the executable
89+ run : cargo build --release --target=x86_64-apple-darwin --target=aarch64-apple-darwin
90+
91+ - name : Build release name
92+ run : |
93+ PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
94+ PKG_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
95+ RELEASE_NAME="${PKG_NAME}_${PKG_VERSION}"
96+ echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
97+ - name : Tar x86_64 binary
98+ run : |
99+ PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
100+ tar -czvf ${{ env.RELEASE_NAME }}-macos-x86_64.tar.gz -C target/x86_64-apple-darwin/release ${PKG_NAME}
101+
102+ - name : Tar arm64 binary
103+ run : |
104+ PKG_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
105+ tar -czvf ${{ env.RELEASE_NAME }}-macos-aarch64.tar.gz -C target/aarch64-apple-darwin/release ${PKG_NAME}
106+
107+ - name : Generate SHA256 checksums
108+ run : |
109+ shasum -a 256 ${{ env.RELEASE_NAME }}-macos-x86_64.tar.gz > ${{ env.RELEASE_NAME }}-macos-x86_64.tar.gz.sha256
110+ shasum -a 256 ${{ env.RELEASE_NAME }}-macos-aarch64.tar.gz > ${{ env.RELEASE_NAME }}-macos-aarch64.tar.gz.sha256
111+
112+ - name : Upload release binaries
113+ uses : softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda
114+ env :
115+ GITHUB_TOKEN : ${{ github.token }}
116+ with :
117+ files : |
118+ ${{ env.RELEASE_NAME }}-macos-x86_64.tar.gz
119+ ${{ env.RELEASE_NAME }}-macos-aarch64.tar.gz
120+ ${{ env.RELEASE_NAME }}-macos-x86_64.tar.gz.sha256
121+ ${{ env.RELEASE_NAME }}-macos-aarch64.tar.gz.sha256
122+ # crates:
123+ # runs-on: ubuntu-latest
124+ # needs: [linux_windows, macos]
125+ # steps:
126+ # - name: Publish to crates.io
127+ # - uses: actions/checkout@v3
128+ # - uses: actions-rs/toolchain@v1
129+ # with:
130+ # toolchain: stable
131+ # override: true
132+ # - uses: katyo/publish-crates@v2
133+ # with:
134+ # registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
0 commit comments