-
Notifications
You must be signed in to change notification settings - Fork 11
127 lines (108 loc) · 3.91 KB
/
release.yml
File metadata and controls
127 lines (108 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Inspired by:
# https://github.com/open-contracting/cardinal-rs/blob/main/.github/workflows/release.yml
name: Test & Release
# The name is either "Release vX.X.X" on tag push or the commit message
run-name: ${{ github.ref_name != 'main' && format('Release - {0}', github.ref_name) || github.event.head_commit.message }}
on:
push:
branches: [ "main" ]
tags: [ "v[0-9]+.[0-9]+.[0-9]+" ]
env:
APP_NAME: gitnr
CARGO_TERM_COLOR: always
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with: { components: "clippy" }
- name: Setup Cache
uses: Swatinem/rust-cache@v2
if: github.ref_name == 'main' # Caching doesn't work on tags, so skip it
with:
cache-targets: "true"
cache-on-failure: "true"
cache-all-crates: "true"
- name: Run Clippy
run: cargo clippy --all-targets -- -D warnings
- name: Run Tests
run: cargo test --verbose
setup:
name: Setup
needs: test
runs-on: ubuntu-latest
if: github.ref_name != 'main' # Only run on tag push
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create Draft Release
run: gh release create ${{ github.ref_name }} --verify-tag --draft=true --title="${{ github.ref_name }}"
env: { GH_TOKEN: "${{ secrets.GH_ACTIONS_PAT }}" }
build:
name: Build
needs: setup
runs-on: ${{ matrix.runner }}
if: github.ref_name != 'main' # Only run on tag push
strategy:
matrix:
include:
# == Linux == #
- name: linux-amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- name: linux-arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
# == Windows == #
- name: win-amd64
runner: windows-latest
target: x86_64-pc-windows-msvc
# == MacOS == #
- name: macos-amd64
runner: macos-latest
target: x86_64-apple-darwin
- name: macos-arm64
runner: macos-latest
target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with: { targets: "${{ matrix.target }}" }
- name: Build Binary
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
- name: Release Upload Binary
shell: bash
env: { GH_TOKEN: "${{ secrets.GH_ACTIONS_PAT }}" }
run: |
BIN_SUFFIX=""
if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
BIN_SUFFIX=".exe"
fi
BIN_OUTPUT="target/${{ matrix.target }}/release/${APP_NAME}${BIN_SUFFIX}"
BIN_RELEASE="${APP_NAME}-${{ matrix.name }}${BIN_SUFFIX}"
# Not used as makes it hard to download binary for script setup
BIN_RELEASE_VERSIONED="${APP_NAME}-${{ github.ref_name }}-${{ matrix.name }}${BIN_SUFFIX}"
cp "${BIN_OUTPUT}" "${BIN_RELEASE}"
gh release upload ${{ github.ref_name }} "${BIN_RELEASE}"
release:
name: Release
needs: build
runs-on: ubuntu-latest
if: github.ref_name != 'main' # Only run on tag push
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Publish GitHub Release
run: gh release edit ${{ github.ref_name }} --verify-tag --draft=false
env: { GH_TOKEN: "${{ secrets.GH_ACTIONS_PAT }}" }
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
# This step takes place only after GH release to ensure binaries are available via cargo-binstall
- name: Publish Crates.io Release
run: cargo publish --verbose --locked --token ${{ secrets.CARGO_REGISTRY_TOKEN }}