-
Notifications
You must be signed in to change notification settings - Fork 11
217 lines (183 loc) · 7.62 KB
/
release.yml
File metadata and controls
217 lines (183 loc) · 7.62 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Copyright © 2023 Province of British Columbia
# https://digital.gov.bc.ca/digital-trust
name: Release
on:
push:
branches: [main]
permissions:
contents: write
jobs:
checks:
name: Check version & existing release
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.current_version.outputs.current_version }}
existing_release_info: ${{ steps.check_existing_release.outputs.release_info }}
existing_assets: ${{ steps.check_existing_release.outputs.release_assets }}
already_in_crates_io: ${{ steps.check_in_crates_io.outputs.already_in_crates_io != '' }}
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v4
- name: Get current version
id: current_version
run: |
version="$(cargo -q metadata --no-deps \
| jq -r '.packages[] | select(.name == "indy-cli-rs") | .version')"
echo current_version=$version >> $GITHUB_OUTPUT
echo "$version"
shell: bash
- name: Check existing release
id: check_existing_release
run: |
release_info="$(curl -s https://api.github.com/repos/${{ github.repository }}/releases \
| jq '.[] | select(.name == "v${{ steps.current_version.outputs.current_version }}")')"
# Generate random delimiter as recommended in docs
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
delimiter="$(openssl rand -hex 8)"
echo "release_info<<${delimiter}" >> $GITHUB_OUTPUT
echo "$release_info" >> $GITHUB_OUTPUT
echo "${delimiter}" >> $GITHUB_OUTPUT
echo "existing release info: $release_info"
release_assets="$(echo "$release_info" | jq -c '[.assets[].name]')"
echo "release_assets=${release_assets}" >> $GITHUB_OUTPUT
echo "existing release assets: $release_assets"
shell: bash
- name: Check if already deployed to crates.io
id: check_in_crates_io
run: |
out="$(curl -s https://crates.io/api/v1/crates/indy-cli-rs | jq -r '.versions[] | .num' \
| grep '^${{ steps.current_version.outputs.current_version }}$')"
echo already_in_crates_io=$out >> $GITHUB_OUTPUT
echo "in crates.io check: $out"
shell: bash {0} # to opt-out of default fail-fast behavior
create_release:
name: Create release if needed
runs-on: ubuntu-latest
needs: checks
steps:
- name: Create GitHub Release
if: ${{ !needs.checks.outputs.existing_release_info }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.checks.outputs.current_version }}
name: v${{ needs.checks.outputs.current_version }}
publish_crate:
name: Publish crate
# Enable this when all dependencies are published
if: ${{ false }}
runs-on: ubuntu-latest
needs: [ checks, create_release ]
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Package and verify crate
id: build_crate
run: |
cargo package
# TODO
# - verify that it's not more than crates.io limit (10 MB)
# - explore whether we need to upload another artifact (without extension)
ls -la target/package
cargo package --list
asset_name="$(find target/package -name '*.crate' -printf '%f')"
echo asset_name=$asset_name >> $GITHUB_OUTPUT
shell: bash
- name: Upload crate to GitHub
if: ${{ !needs.checks.outputs.existing_assets || !contains(fromJSON(needs.checks.outputs.existing_assets), steps.build_crate.outputs.asset_name)}}
uses: svenstaro/upload-release-action@v2
with:
file: target/package/${{ steps.build_crate.outputs.asset_name }}
asset_name: ${{ steps.build_crate.outputs.asset_name }}
tag: v${{ needs.checks.outputs.current_version }}
release_name: v${{ needs.checks.outputs.current_version }}
- name: Publish to crates.io
if: ${{ needs.checks.outputs.already_in_crates_io == 'false' }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
shell: bash
publish_assets:
name: Publish assets
needs: [ checks, create_release ]
strategy:
matrix:
include:
- arch: linux-x86_64
os: ubuntu-latest
artifact: indy-cli-rs
target: x86_64-unknown-linux-gnu
# using cross here to build against an older glibc for compatibility
use_cross: true
- arch: windows-x86_64
os: windows-latest
artifact: indy-cli-rs.exe
target: x86_64-pc-windows-msvc
- arch: darwin-x86_64
os: macos-11
artifact: indy-cli-rs
target: x86_64-apple-darwin
- arch: darwin-aarch64
os: macos-11
artifact: indy-cli-rs
target: aarch64-apple-darwin
# beta or nightly required for aarch64-apple-darwin target
toolchain: beta
defaults:
run:
working-directory: .
env:
asset_name: indy-cli-rs-${{ needs.checks.outputs.current_version }}-${{ matrix.arch }}.tar.gz
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain || 'stable' }}
targets: ${{ matrix.target }}
- name: Cache cargo resources
uses: Swatinem/rust-cache@v2
- name: Check existing release asset
id: check_existing
run: |
# GitHub actions do not support skipping subsequent job steps (see https://github.com/actions/runner/issues/662)
# So here we're using output value with separate conditions for every subsequent step
echo "asset_exists=${{ needs.checks.outputs.existing_assets && contains(fromJSON(needs.checks.outputs.existing_assets), env.asset_name) }}" >> $GITHUB_OUTPUT
shell: bash
- name: Build
if: ${{ steps.check_existing.outputs.asset_exists != 'true' && !matrix.use_cross }}
run: cargo build --target ${{ matrix.target }} --locked --release
- name: Build (cross)
if: ${{ steps.check_existing.outputs.asset_exists != 'true' && matrix.use_cross }}
run: |
cargo install --bins --git https://github.com/rust-embedded/cross --tag v0.2.4 cross
cross build --target ${{ matrix.target }} --locked --release
- name: Create release assets directory
if: ${{ steps.check_existing.outputs.asset_exists != 'true' }}
run: |
mkdir release-assets
cp target/${{ matrix.target }}/release/${{ matrix.artifact }} release-assets/
- name: Pack asset
if: ${{ steps.check_existing.outputs.asset_exists != 'true' }}
uses: a7ul/tar-action@v1.2.0
with:
command: c
cwd: ./release-assets
files: .
outPath: "indy-cli-rs.tar.gz"
- name: Upload asset to GitHub
if: ${{ steps.check_existing.outputs.asset_exists != 'true' }}
uses: svenstaro/upload-release-action@v2
with:
file: indy-cli-rs.tar.gz
tag: v${{ needs.checks.outputs.current_version }}
release_name: v${{ needs.checks.outputs.current_version }}
asset_name: ${{ env.asset_name }}