-
-
Notifications
You must be signed in to change notification settings - Fork 89
205 lines (182 loc) · 6.49 KB
/
release.yaml
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
# Taken from ripgrep with modifications
# Taken from mitsuhiko/rye with modifications
#
# Reference:
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
name: release
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
inputs:
version:
type: string
description: "Release version"
required: true
dry-run:
type: choice
description: "Dry Run"
options:
- "no"
- "yes"
required: true
jobs:
create-release:
name: create-release
runs-on: ubuntu-22.04
outputs:
gql_version: ${{ env.GQL_VERSION }}
gql_dry_run: ${{ env.GQL_DRY_RUN }}
steps:
- name: Inputs from workflow dispatch
shell: bash
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "GQL_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
echo "GQL_DRY_RUN=${{ github.event.inputs.dry-run }}" >> $GITHUB_ENV
echo "GQL_VERSION: ${{ github.event.inputs.version }}"
echo "GQL_DRY_RUN: ${{ github.event.inputs.dry-run }}"
- name: Checkout repository
uses: actions/checkout@v3
- name: Get the release version from the tag
shell: bash
if: env.GQL_VERSION == ''
run: |
# Apparently, this is the right way to get a tag name. Really?
#
# See: https://gh.neting.ccmunity/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
echo "GQL_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "version is: ${{ env.GQL_VERSION }}"
- name: Create GitHub release
id: release
if: env.GQL_DRY_RUN != 'yes'
env:
GH_TOKEN: ${{ secrets.TOKEN }}
run: gh release create --draft --title "${{ env.GQL_VERSION }}" "${{ env.GQL_VERSION }}"
build-release:
name: build-release
needs: ["create-release"]
runs-on: ${{ matrix.os }}
env:
# For some builds, we use cross to test on 32-bit and big-endian
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS: ""
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# Emit backtraces on panics.
RUST_BACKTRACE: 1
strategy:
matrix:
build: [linux, macos, macos-arm, win-msvc, win32-msvc]
include:
- build: linux
os: ubuntu-22.04
rust: stable
target: x86_64-unknown-linux-musl
name: x86_64-linux
- build: linux-arm
os: ubuntu-22.04
rust: stable
target: aarch64-unknown-linux-musl
name: aarch64-linux
- build: macos
os: macos-12
rust: stable
target: x86_64-apple-darwin
name: x86_64-macos
- build: macos-arm
os: macos-12
rust: stable
target: aarch64-apple-darwin
name: aarch64-macos
- build: win-msvc
os: windows-2022
rust: stable
target: x86_64-pc-windows-msvc
name: x86_64-windows
- build: win32-msvc
os: windows-2022
rust: stable
target: i686-pc-windows-msvc
name: x86-windows
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Use Cross
shell: bash
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
- name: Build release file
shell: bash
run: |
chmod +x scripts/cargo-out-dir
outdir="$(scripts/cargo-out-dir "${{ env.TARGET_DIR }}")"
bin="gql-${{ matrix.name }}"
if [ "${{ matrix.os }}" = "windows-2022" ]; then
cp "target/${{ matrix.target }}/release/gitql.exe" "$bin.exe"
python scripts/sha256.py $bin.exe > "$bin.exe.sha256"
echo "ASSET=$bin.exe" >> $GITHUB_ENV
echo "SHA256_FILE=$bin.exe.sha256" >> $GITHUB_ENV
else
cp "target/${{ matrix.target }}/release/gitql" "$bin"
gzip "$bin"
python scripts/sha256.py $bin.gz > "$bin.gz.sha256"
echo "ASSET=$bin.gz" >> $GITHUB_ENV
echo "SHA256_FILE=$bin.gz.sha256" >> $GITHUB_ENV
fi
- name: Upload release archive
if: ${{ needs.create-release.outputs.gql_dry_run }} != 'yes'
env:
GH_TOKEN: ${{ secrets.TOKEN }}
run: |
gh release upload "${{ needs.create-release.outputs.gql_version }}" "${{ env.ASSET }}"
gh release upload "${{ needs.create-release.outputs.gql_version }}" "${{ env.SHA256_FILE }}"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ASSET }}
path: ${{ env.ASSET }}
- name: Upload artifact hash
uses: actions/upload-artifact@v3
with:
name: ${{ env.SHA256_FILE }}
path: ${{ env.SHA256_FILE }}
write-release-meta:
name: write-release-meta
runs-on: ubuntu-22.04
needs: ["create-release", "build-release"]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Upload Release Meta
if: ${{ needs.create-release.outputs.gql_dry_run }} != 'yes'
shell: bash
env:
GH_TOKEN: ${{ secrets.TOKEN }}
run: |
gh run download $GH_RUNID -D artifacts-tmp -p "*.sha256"
python scripts/summarize-release.py "${{ needs.create-release.outputs.gql_version }}" artifacts-tmp > MANIFEST.json
gh release upload "${{ needs.create-release.outputs.gql_version }}" MANIFEST.json
- name: Upload artifact hash
uses: actions/upload-artifact@v3
with:
name: MANIFEST.json
path: MANIFEST.json