-
Notifications
You must be signed in to change notification settings - Fork 1
195 lines (175 loc) · 6.91 KB
/
merge.yml
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
---
name: CI on Main
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
compute-next-semantic-version:
permissions:
id-token: "write"
contents: "write" # FIXME this should not require write permission.
uses: semantic-release-action/next-release-version/.github/workflows/next-release-version.yml@v4
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt
- name: run cargo test
run: cargo test --all-features
create-new-release:
name: Create the new release as a draft
# If the version is empty, it means there is no new version to publish.
if: ${{ needs.compute-next-semantic-version.outputs.new-release-version != '' }}
permissions:
id-token: "write"
contents: "write" # This is required to create the GH release
runs-on: ubuntu-latest
needs:
- compute-next-semantic-version
env:
NEW_TAG: "v${{ needs.compute-next-semantic-version.outputs.new-release-version }}"
outputs:
release-id: ${{ steps.create-new-release.outputs.release-id }}
release-url: ${{ steps.create-new-release.outputs.release-url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if a release already exists for that version
run: |
current_release=$(
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.NEW_TAG }}
)
error_message=$(echo "$new_release" | jq ".message // empty")
if [[ -n "$error_message" ]]; then
echo "Could not verify if a release exist for ${{ env.NEW_TAG }}: $error_message"
exit 1
fi
current_release_name=$(echo "$current_release" | jq ".name // empty")
if [[ -n "$current_release_name" ]]; then
echo "A release already exists for version ${{ env.NEW_TAG }}."
exit 1
fi
- name: Create the new release
id: create-new-release
run: |
echo "Creating new release ${{ env.NEW_TAG }}"
release_payload=$(jq -n '{
"tag_name": "${{ env.NEW_TAG }}",
"target_commitish": "${{ github.sha }}",
"name": "${{ env.NEW_TAG }}",
"prerelease": false,
"draft": true,
"generate_release_notes": true
}')
new_release=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d "$release_payload"
)
new_release_id=$(echo "$new_release" | jq ".id")
if [[ "$new_release_id" == "null" ]]; then
error_message=$(echo "$new_release" | jq ".message")
echo "Could not create new release: $error_message"
exit 1
fi
echo "release-id=$new_release_id" >> "$GITHUB_OUTPUT"
echo "release-id = $new_release_id"
new_release_url="https://uploads.github.com/repos/${{ github.repository }}/releases/$new_release_id/assets"
echo "release-url=$new_release_url" >> "$GITHUB_OUTPUT"
echo "release-url = $new_release_url"
build-binary:
runs-on: ubuntu-latest
permissions:
id-token: "write"
contents: "write" # This is required to add artifacts to the GH release
needs:
- create-new-release
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@da36cb69b1c3247ad7a1f931ebfd954a1105ef14 # v14
- name: Build the artifact
run: |
nix develop .#musl -c cargo build --release
- name: Add artifact to the release
env:
binary_path: "nix2sbom-x86_64-unknown-linux-musl"
artifact_path: "./target/x86_64-unknown-linux-musl/release/nix2sbom"
run: |
checksum_path="${{ env.binary_path }}.sha256sum"
cp "$artifact_path" "$binary_path"
sha256sum "${{ env.binary_path }}" > "$checksum_path"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${{ needs.create-new-release.outputs.release-url }}?name=${{ env.binary_path }}&label=${{ env.binary_path }}" \
--data-binary "@${{ env.binary_path }}"
echo "Uploaded the artifact to the GitHub release"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${{ needs.create-new-release.outputs.release-url }}?name=$checksum_path&label=$checksum_path" \
--data-binary "@$checksum_path"
echo "Uploaded the artifact checksum to the GitHub release"
publish-github-release:
name: Publish (undraft) the release
runs-on: ubuntu-latest
permissions:
id-token: "write"
contents: "write"
needs:
- create-new-release
- build-binary
steps:
- name: Publish the release
run: |
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases/${{ needs.create-new-release.outputs.release-id }} \
-d '{"draft": false}'
publish-flakehub-release:
# If the version is empty, it means there is no new version to publish.
if: ${{ needs.compute-next-semantic-version.outputs.new-release-version != '' }}
needs:
- test
- compute-next-semantic-version
- publish-github-release
runs-on: ubuntu-latest
permissions:
id-token: "write"
contents: "read"
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@da36cb69b1c3247ad7a1f931ebfd954a1105ef14 # v14
- run: |
: build the nix flake
nix build .#
- uses: DeterminateSystems/flakehub-push@8da9e38b7e77f2b0a8aa08a22e57cc5c6316ea72 # v5
with:
visibility: "public"
rolling: false
tag: "v${{ needs.compute-next-semantic-version.outputs.new-release-version }}"