Skip to content

Commit 4013d73

Browse files
authored
Update GH actions (#17)
1 parent 382bd6d commit 4013d73

File tree

4 files changed

+94
-52
lines changed

4 files changed

+94
-52
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ updates:
88
cargo-dependencies:
99
patterns:
1010
- "*"
11+
cooldown:
12+
default-days: 7

.github/workflows/build.yml

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ on:
1010
- main
1111
workflow_dispatch:
1212

13-
permissions:
14-
contents: write
15-
packages: write
16-
1713
jobs:
1814
check-version:
15+
permissions:
16+
contents: read
1917
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
2018
runs-on: ubuntu-latest
2119
outputs:
@@ -24,22 +22,26 @@ jobs:
2422
should_run: ${{ steps.decide.outputs.should_run }}
2523
steps:
2624
- name: Checkout
27-
uses: actions/checkout@v4
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2826
with:
2927
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
28+
persist-credentials: false
3029

3130
- name: Read version
3231
id: version
32+
shell: bash
3333
run: |
3434
version=$(awk -F' *= *' '$1 == "version" { gsub(/"/, "", $2); print $2; exit }' Cargo.toml)
3535
echo "version=$version" >> "$GITHUB_OUTPUT"
3636
3737
- name: Check release existence
3838
id: release_check
39-
uses: actions/github-script@v7
39+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
40+
env:
41+
VERSION: ${{ steps.version.outputs.version }}
4042
with:
4143
script: |
42-
const tag = `${{ steps.version.outputs.version }}`;
44+
const tag = process.env.VERSION;
4345
try {
4446
await github.rest.repos.getReleaseByTag({
4547
owner: context.repo.owner,
@@ -57,28 +59,35 @@ jobs:
5759
5860
- name: Decide run
5961
id: decide
62+
shell: bash
63+
env:
64+
RELEASE_EXISTS: ${{ steps.release_check.outputs.release_exists }}
6065
run: |
61-
if [[ "${{ steps.release_check.outputs.release_exists }}" == "false" ]]; then
66+
if [[ "$RELEASE_EXISTS" == "false" ]]; then
6267
echo "should_run=true" >> "$GITHUB_OUTPUT"
6368
else
6469
echo "should_run=false" >> "$GITHUB_OUTPUT"
6570
fi
6671
6772
build-database:
73+
permissions:
74+
contents: read
6875
runs-on: ubuntu-latest
6976
needs: check-version
7077
if: needs.check-version.outputs.should_run == 'true'
7178
steps:
7279
- name: Checkout
73-
uses: actions/checkout@v4
80+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7481
with:
7582
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
83+
persist-credentials: false
7684

77-
- name: Set up Rust
78-
uses: dtolnay/rust-toolchain@stable
85+
- name: Setup Rust
86+
shell: bash
87+
run: rustup update stable && rustup default stable
7988

8089
- name: Cache cargo
81-
uses: actions/cache@v4
90+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
8291
with:
8392
path: |
8493
~/.cargo/registry
@@ -87,33 +96,37 @@ jobs:
8796
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
8897

8998
- name: Create data directory
99+
shell: bash
90100
run: mkdir -p data
91101

92102
- name: Restore bag.bin cache
93103
id: bag_cache
94-
uses: actions/cache/restore@v4
104+
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
95105
with:
96106
path: data/bag.bin
97107
key: bag-bin-${{ needs.check-version.outputs.version }}
98108

99109
- name: Create bag.bin
100110
if: steps.bag_cache.outputs.cache-hit != 'true'
111+
shell: bash
101112
run: cargo run --release --bin create-db --features "create"
102113

103114
- name: Save bag.bin cache
104115
if: steps.bag_cache.outputs.cache-hit != 'true'
105-
uses: actions/cache/save@v4
116+
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
106117
with:
107118
path: data/bag.bin
108119
key: bag-bin-${{ needs.check-version.outputs.version }}
109120

110121
- name: Upload bag.bin
111-
uses: actions/upload-artifact@v4
122+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
112123
with:
113124
name: bag.bin
114125
path: data/bag.bin
115126

116127
build:
128+
permissions:
129+
contents: read
117130
needs: [ check-version, build-database ]
118131
if: needs.check-version.outputs.should_run == 'true'
119132
runs-on: ${{ matrix.os }}
@@ -135,66 +148,77 @@ jobs:
135148
artifact: bag-service-macos-arm64
136149
steps:
137150
- name: Checkout
138-
uses: actions/checkout@v4
151+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
139152
with:
140153
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
154+
persist-credentials: false
141155

142156
- name: Download bag.bin
143-
uses: actions/download-artifact@v4
157+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
144158
with:
145159
name: bag.bin
146160
path: data
147161

148-
- name: Set up Rust
149-
uses: dtolnay/rust-toolchain@stable
150-
with:
151-
targets: ${{ matrix.target }}
162+
- name: Setup Rust
163+
shell: bash
164+
run: >
165+
rustup update stable &&
166+
rustup default stable &&
167+
rustup target add --toolchain stable ${{ matrix.target }}
152168
153169
- name: Optionally install musl-tools
154170
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'arm64-unknown-linux-musl'
171+
shell: bash
155172
run: sudo apt-get install -y musl-tools
156173

157-
- uses: Swatinem/rust-cache@v2
174+
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
158175

159176
- name: Build
177+
shell: bash
160178
env:
161179
CC_aarch64_unknown_linux_musl: ${{ matrix.target == 'aarch64-unknown-linux-musl' && 'musl-gcc' || '' }}
162180
run: cargo build --release --bin bag-service --target ${{ matrix.target }}
163181

164182
- name: Package
183+
shell: bash
165184
run: |
166185
mkdir -p dist
167186
cp target/${{ matrix.target }}/release/bag-service dist/${{ matrix.artifact }}
168187
169188
- name: Upload artifact
170-
uses: actions/upload-artifact@v4
189+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
171190
with:
172191
name: ${{ matrix.artifact }}
173192
path: dist/${{ matrix.artifact }}
174193

175194
docker:
195+
permissions:
196+
contents: read
197+
packages: write
176198
needs:
177199
- check-version
178200
- build
179201
if: needs.check-version.outputs.should_run == 'true'
180202
runs-on: ubuntu-latest
181203
steps:
182-
- uses: actions/checkout@v6
204+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
205+
with:
206+
persist-credentials: false
183207
- name: Download linux x64 artifact
184-
uses: actions/download-artifact@v4
208+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
185209
with:
186210
name: bag-service-linux-x64
187211
path: dist
188212

189213
- name: Login to GitHub Container Registry
190-
uses: docker/login-action@v3
214+
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
191215
with:
192216
registry: ghcr.io
193217
username: ${{ github.actor }}
194218
password: ${{ secrets.GITHUB_TOKEN }}
195219

196220
- name: Build and push docker image
197-
uses: docker/build-push-action@v6
221+
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
198222
with:
199223
file: Dockerfile
200224
push: true
@@ -203,44 +227,49 @@ jobs:
203227
tags: "ghcr.io/tweedegolf/bag-address-lookup:${{ needs.check-version.outputs.version }},ghcr.io/tweedegolf/bag-address-lookup:latest"
204228

205229
release:
230+
permissions:
231+
contents: write
206232
needs:
207233
- check-version
208234
- build
209235
if: needs.check-version.outputs.should_run == 'true'
210236
runs-on: ubuntu-latest
211237
steps:
212238
- name: Download linux x64 artifact
213-
uses: actions/download-artifact@v4
239+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
214240
with:
215241
name: bag-service-linux-x64
216242
path: dist
217243

218244
- name: Download linux arm64 artifact
219-
uses: actions/download-artifact@v4
245+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
220246
with:
221247
name: bag-service-linux-arm64
222248
path: dist
223249

224250
- name: Download macos x64 artifact
225-
uses: actions/download-artifact@v4
251+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
226252
with:
227253
name: bag-service-macos-x64
228254
path: dist
229255

230256
- name: Download macos arm64 artifact
231-
uses: actions/download-artifact@v4
257+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
232258
with:
233259
name: bag-service-macos-arm64
234260
path: dist
235261

236262
- name: Create release
237-
uses: softprops/action-gh-release@v2
238-
with:
239-
tag_name: ${{ needs.check-version.outputs.version }}
240-
name: Version ${{ needs.check-version.outputs.version }}
241-
generate_release_notes: true
242-
files: |
243-
dist/bag-service-linux-x64
244-
dist/bag-service-linux-arm64
245-
dist/bag-service-macos-x64
263+
shell: bash
264+
env:
265+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
266+
VERSION: ${{ needs.check-version.outputs.version }}
267+
GH_REPO: ${{ github.repository }}
268+
run: |
269+
gh release create "$VERSION" \
270+
--title "Version $VERSION" \
271+
--generate-notes \
272+
dist/bag-service-linux-x64 \
273+
dist/bag-service-linux-arm64 \
274+
dist/bag-service-macos-x64 \
246275
dist/bag-service-macos-arm64

.github/workflows/check.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,31 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
permissions: {}
11+
1012
jobs:
1113
check:
14+
permissions:
15+
contents: read
1216
runs-on: ubuntu-latest
1317
steps:
1418
- name: Checkout
15-
uses: actions/checkout@v4
16-
17-
- name: Set up Rust
18-
uses: dtolnay/rust-toolchain@stable
19+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1920
with:
20-
components: rustfmt, clippy
21+
persist-credentials: false
22+
23+
- name: Setup Rust
24+
shell: bash
25+
run: >
26+
rustup update stable &&
27+
rustup default stable &&
28+
rustup component add --toolchain stable rustfmt clippy
2129
2230
- name: Create an empty database file
2331
run: mkdir -p data && touch data/bag.bin
2432

2533
- name: Cache cargo
26-
uses: actions/cache@v4
34+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
2735
with:
2836
path: |
2937
~/.cargo/registry

.github/workflows/monthly-release.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1818
with:
1919
persist-credentials: true
2020

21-
- name: Set up Rust
22-
uses: dtolnay/rust-toolchain@stable
21+
- name: Setup Rust
22+
shell: bash
23+
run: rustup update stable && rustup default stable
2324

2425
- name: Cache cargo
25-
uses: actions/cache@v4
26+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
2627
with:
2728
path: |
2829
~/.cargo/registry
@@ -61,15 +62,17 @@ jobs:
6162
run: cargo test --all-features
6263

6364
- name: Commit version bump
65+
env:
66+
VERSION: ${{ steps.bump.outputs.version }}
6467
run: |
6568
git add Cargo.toml Cargo.lock
66-
git commit -m "chore: monthly release v${{ steps.bump.outputs.version }}"
69+
git commit -m "chore: monthly release v${VERSION}"
6770
6871
- name: Push
6972
run: git push origin HEAD:main
7073

7174
- name: Trigger build workflow
72-
uses: actions/github-script@v7
75+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
7376
with:
7477
script: |
7578
await github.rest.actions.createWorkflowDispatch({

0 commit comments

Comments
 (0)