Skip to content

Commit c2e9adb

Browse files
authored
chore: tightened GitHub Actions permissions (#165)
1 parent f27e6af commit c2e9adb

3 files changed

Lines changed: 58 additions & 24 deletions

File tree

.github/workflows/build-wasm.yml

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ on:
44
workflow_dispatch:
55
inputs:
66
sqlite_ref:
7-
description: 'SQLite reference (tag, branch, or commit, or "latest")'
7+
description: 'Full commit SHA from SQLite repository'
88
required: true
9-
default: 'master'
109

11-
permissions:
12-
contents: write
13-
pull-requests: write
10+
permissions: {}
1411

1512
jobs:
1613
build:
1714
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v6
@@ -25,23 +25,15 @@ jobs:
2525
id: resolve-ref
2626
run: |
2727
SQLITE_REF="${{ github.event.inputs.sqlite_ref }}"
28-
if [ "$SQLITE_REF" = "latest" ]; then
29-
echo "Fetching latest tag..."
30-
LATEST_TAG=$(git ls-remote --tags --sort="v:refname" https://github.com/sqlite/sqlite.git "refs/tags/version-*" | tail -n 1 | cut -f 2 | sed 's/refs\/tags\///')
31-
echo "Latest tag found: $LATEST_TAG"
32-
SQLITE_REF="$LATEST_TAG"
28+
if ! [[ "$SQLITE_REF" =~ ^[0-9a-fA-F]{40}$ ]]; then
29+
echo "Expected a full 40-character commit SHA, got: '$SQLITE_REF'"
30+
exit 1
3331
fi
3432
35-
# Get the full commit SHA
3633
SQLITE_SHA=$(git ls-remote https://github.com/sqlite/sqlite.git "$SQLITE_REF" | head -n 1 | cut -f 1)
37-
if [ -z "$SQLITE_SHA" ]; then
38-
# If not found, maybe it's a tag that needs refs/tags/ prefix or it's already a SHA
39-
SQLITE_SHA=$(git ls-remote https://github.com/sqlite/sqlite.git "refs/tags/$SQLITE_REF" | head -n 1 | cut -f 1)
40-
fi
41-
42-
if [ -z "$SQLITE_SHA" ]; then
43-
# Fallback: assume it's a SHA if ls-remote didn't find it as a ref
44-
SQLITE_SHA="$SQLITE_REF"
34+
if [ -z "$SQLITE_SHA" ] || [ "$SQLITE_SHA" != "$SQLITE_REF" ]; then
35+
echo "Commit SHA '$SQLITE_REF' was not found in https://github.com/sqlite/sqlite.git"
36+
exit 1
4537
fi
4638
4739
echo "sqlite_ref=$SQLITE_REF" >> $GITHUB_OUTPUT
@@ -70,8 +62,6 @@ jobs:
7062
context: .
7163
load: true
7264
tags: sqlite-wasm-builder:env
73-
cache-from: type=gha
74-
cache-to: type=gha,mode=max
7565

7666
- name: Run build
7767
if: steps.check-branch.outputs.skip != 'true'

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: CI
22

3-
permissions:
4-
contents: read
5-
pull-requests: read
3+
permissions: {}
64

75
on:
86
push:
@@ -22,6 +20,8 @@ jobs:
2220
type-check:
2321
name: Type check
2422
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
2525
steps:
2626
- name: Checkout repo
2727
uses: actions/checkout@v6
@@ -37,6 +37,8 @@ jobs:
3737
format:
3838
name: Format check
3939
runs-on: ubuntu-latest
40+
permissions:
41+
contents: read
4042
steps:
4143
- name: Checkout repo
4244
uses: actions/checkout@v6
@@ -52,6 +54,8 @@ jobs:
5254
test-browser:
5355
name: Run browser tests
5456
runs-on: ubuntu-latest
57+
permissions:
58+
contents: read
5559
steps:
5660
- name: Checkout repo
5761
uses: actions/checkout@v6
@@ -92,6 +96,8 @@ jobs:
9296
test-node:
9397
name: Run node tests (Node ${{ matrix.node-version }})
9498
runs-on: ubuntu-latest
99+
permissions:
100+
contents: read
95101
strategy:
96102
fail-fast: false
97103
matrix:

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish package
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions: {}
9+
10+
jobs:
11+
publish-npm:
12+
name: Publish to npm (OIDC)
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
id-token: write
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v6
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Setup environment (node + install)
24+
uses: ./.github/actions/node-setup
25+
with:
26+
node-version: 24
27+
28+
- name: Build and validate package
29+
run: npm run prepublishOnly
30+
31+
- name: Configure npm for OIDC trusted publishing
32+
uses: actions/setup-node@v6
33+
with:
34+
node-version: 24
35+
registry-url: https://registry.npmjs.org
36+
37+
- name: Publish to npm
38+
run: npm publish --provenance --access public

0 commit comments

Comments
 (0)