Skip to content

Commit 8af43d4

Browse files
committed
ci: add release workflow
1 parent 1b40e07 commit 8af43d4

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

.github/workflows/release.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- v[0-9]+.[0-9]+.[0-9]+
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
name: release (${{ matrix.job.target }})
14+
runs-on: ${{ matrix.job.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
job:
19+
- { target: aarch64-apple-darwin, os: macos-latest }
20+
# - { target: aarch64-pc-windows-gnu, os: ubuntu-latest }
21+
# - { target: aarch64-pc-windows-msvc, os: windows-latest }
22+
- { target: aarch64-unknown-linux-gnu, os: ubuntu-latest }
23+
# - { target: aarch64-unknown-linux-musl, os: ubuntu-latest }
24+
- { target: x86_64-apple-darwin, os: macos-latest }
25+
- { target: x86_64-pc-windows-gnu, os: ubuntu-latest }
26+
- { target: x86_64-pc-windows-msvc, os: windows-latest }
27+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
28+
# - { target: x86_64-unknown-linux-musl, os: ubuntu-latest }
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
- name: Cache
33+
uses: actions/cache@v3
34+
with:
35+
path: |
36+
~/.cargo/bin/
37+
~/.cargo/registry/index/
38+
~/.cargo/registry/cache/
39+
~/.cargo/git/db/
40+
target/
41+
key: ${{ runner.os }}-${{ matrix.job.target }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
42+
- name: Install Rust toolchain
43+
uses: actions-rs/toolchain@v1
44+
with:
45+
toolchain: stable
46+
target: ${{ matrix.job.target }}
47+
override: true
48+
profile: minimal
49+
- name: Build
50+
uses: actions-rs/cargo@v1
51+
with:
52+
use-cross: ${{ matrix.job.os == 'ubuntu-latest' }}
53+
command: build
54+
args: --locked --release --target=${{ matrix.job.target }}
55+
- name: Archive
56+
id: archive
57+
shell: bash
58+
run: |
59+
# Set $BIN_NAME
60+
case ${{ matrix.job.target }} in
61+
*-pc-windows-*) BIN_NAME_SUFFIX='.exe' ;;
62+
*) BIN_NAME_SUFFIX='' ;;
63+
esac
64+
BIN_NAME="vpm-repos-gen${BIN_NAME_SUFFIX}"
65+
66+
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" .
67+
68+
# Set $ARCHIVE_PATH
69+
RELEASE_VERSION="${GITHUB_REF#refs/tags/v}"
70+
ARCHIVE_BASENAME="vpm-repos-gen-${RELEASE_VERSION}-${{ matrix.job.target }}"
71+
case ${{ matrix.job.target }} in
72+
*-pc-windows-*) ARCHIVE_SUFFIX='.zip' ;;
73+
*) ARCHIVE_SUFFIX='.tar.gz' ;;
74+
esac
75+
ARCHIVE_PATH="${ARCHIVE_BASENAME}${ARCHIVE_SUFFIX}"
76+
77+
# Create archive
78+
case ${{ matrix.job.target }} in
79+
*-pc-windows-*) 7z a "${ARCHIVE_PATH}" "${BIN_NAME}" LICENSE-APACHE LICENSE-MIT README.md ;;
80+
*) tar -czf "${ARCHIVE_PATH}" "${BIN_NAME}" LICENSE-APACHE LICENSE-MIT README.md ;;
81+
esac
82+
83+
echo "ARCHIVE_PATH=${ARCHIVE_PATH}" >> "$GITHUB_ENV"
84+
- name: Publish release
85+
uses: softprops/action-gh-release@v1
86+
with:
87+
files: ${{ env.ARCHIVE_PATH }}
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)