-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (148 loc) · 4.72 KB
/
Copy pathrelease.yml
File metadata and controls
169 lines (148 loc) · 4.72 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
backfill_github_releases:
description: Create or update GitHub Releases for every stable tag
required: false
default: false
type: boolean
permissions:
contents: read
packages: read
env:
CARGO_TERM_COLOR: always
jobs:
verify:
name: Verify Release Metadata
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.release.outputs.release_tag }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Fetch Protected Main
run: git fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main
- name: Verify Release Commit Provenance
run: ./scripts/check-release-provenance.sh "$GITHUB_SHA" origin/main
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache Cargo Artifacts
uses: Swatinem/rust-cache@v2
- name: Resolve Release Tag
id: release
run: |
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
version="$(sed -nE 's/^version = "([^"]+)"/\1/p' Cargo.toml | head -n1)"
echo "release_tag=v${version}" >> "$GITHUB_OUTPUT"
else
echo "release_tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Check Release Metadata
run: ./scripts/check-release.sh "${{ steps.release.outputs.release_tag }}"
- name: List hubuum_client Package Contents
run: cargo package --list -p hubuum_client
required-checks:
name: Required Release Checks
needs: verify
permissions:
contents: read
packages: read
uses: ./.github/workflows/ci.yml
with:
run_semver: true
secrets: inherit
publish-hubuum-client:
name: Publish hubuum_client
runs-on: ubuntu-latest
needs:
- verify
- required-checks
if: github.event_name == 'push'
environment: release
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo Artifacts
uses: Swatinem/rust-cache@v2
- name: Authenticate to crates.io
id: auth
uses: rust-lang/crates-io-auth-action@v1
- name: Check whether hubuum_client is already published
id: published
run: |
version="$(sed -nE 's/^version = "([^"]+)"/\1/p' Cargo.toml | head -n1)"
tmpdir="$(mktemp -d)"
mkdir -p "${tmpdir}/src"
printf "" > "${tmpdir}/src/lib.rs"
printf '%s\n' \
'[package]' \
'name = "hubuum-client-release-probe"' \
'version = "0.0.0"' \
'edition = "2024"' \
'' \
'[dependencies]' \
"hubuum_client = \"=${version}\"" \
> "${tmpdir}/Cargo.toml"
if cargo metadata --manifest-path "${tmpdir}/Cargo.toml" --format-version 1 >/dev/null 2>&1; then
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish hubuum_client
if: steps.published.outputs.published != 'true'
run: |
set +e
output="$(cargo publish -p hubuum_client --locked 2>&1)"
status=$?
set -e
printf '%s\n' "$output"
if [ "$status" -eq 0 ]; then
exit 0
fi
if printf '%s\n' "$output" | grep -Fq "already exists on crates.io index"; then
exit 0
fi
exit "$status"
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
github-release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs:
- verify
- publish-hubuum-client
if: >-
always() &&
needs.verify.result == 'success' &&
((github.event_name == 'push' && needs.publish-hubuum-client.result == 'success') ||
(github.event_name == 'workflow_dispatch' && inputs.backfill_github_releases))
permissions:
contents: write
steps:
- name: Checkout All Tags
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Create or Update GitHub Release
if: github.event_name == 'push'
run: ./scripts/publish-github-release.sh "${{ needs.verify.outputs.release_tag }}" --latest
env:
GH_TOKEN: ${{ github.token }}
- name: Create or Update Stable GitHub Releases
if: github.event_name == 'workflow_dispatch'
run: ./scripts/backfill-github-releases.sh
env:
GH_TOKEN: ${{ github.token }}