Skip to content

Commit ad1436d

Browse files
committed
Harden GitHub workflows against action supply-chain risk
1 parent 47fef58 commit ad1436d

3 files changed

Lines changed: 58 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,19 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v4
18+
- name: Checkout repository
19+
run: |
20+
rm -rf .git
21+
git init .
22+
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
23+
git fetch --depth=1 origin "${{ github.sha }}"
24+
git checkout --detach FETCH_HEAD
1925
2026
- name: Install Rust
2127
run: |
2228
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
2329
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
2430
25-
- name: Cache cargo
26-
uses: actions/cache@v4
27-
with:
28-
path: |
29-
~/.cargo/registry
30-
~/.cargo/git
31-
target
32-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
33-
3431
- name: Verify assets are up to date
3532
run: |
3633
make clean

.github/workflows/publish-crates.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@ jobs:
1414
runs-on: ubuntu-latest
1515

1616
steps:
17-
- uses: actions/checkout@v4
17+
- name: Checkout repository
18+
run: |
19+
rm -rf .git
20+
git init .
21+
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
22+
git fetch --depth=1 origin "${{ github.sha }}"
23+
git checkout --detach FETCH_HEAD
1824
1925
- name: Install Rust
2026
run: |
2127
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
2228
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
2329
24-
- name: Cache cargo
25-
uses: actions/cache@v4
26-
with:
27-
path: |
28-
~/.cargo/registry
29-
~/.cargo/git
30-
target
31-
key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
32-
3330
- name: Check formatting
3431
run: cargo fmt --all -- --check
3532

.github/workflows/release.yml

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,19 @@ jobs:
2222
runs-on: ubuntu-latest
2323

2424
steps:
25-
- uses: actions/checkout@v4
25+
- name: Checkout repository
26+
run: |
27+
rm -rf .git
28+
git init .
29+
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
30+
git fetch --depth=1 origin "${{ github.sha }}"
31+
git checkout --detach FETCH_HEAD
2632
2733
- name: Install Rust
2834
run: |
2935
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
3036
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
3137
32-
- name: Cache cargo
33-
uses: actions/cache@v4
34-
with:
35-
path: |
36-
~/.cargo/registry
37-
~/.cargo/git
38-
target
39-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
40-
4138
- name: Check formatting
4239
run: cargo fmt --all -- --check
4340

@@ -58,9 +55,14 @@ jobs:
5855
needs: [test]
5956

6057
steps:
61-
- uses: actions/checkout@v4
62-
with:
63-
fetch-depth: 0
58+
- name: Checkout repository
59+
run: |
60+
rm -rf .git
61+
git init .
62+
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
63+
git fetch --force --tags origin "+refs/heads/*:refs/remotes/origin/*"
64+
git fetch --force origin "${{ github.sha }}"
65+
git checkout --detach FETCH_HEAD
6466
6567
- name: Get version
6668
id: version
@@ -89,19 +91,32 @@ jobs:
8991
echo "EOF" >> $GITHUB_OUTPUT
9092
9193
- name: Create Release
92-
uses: softprops/action-gh-release@v1
93-
with:
94-
name: v${{ steps.version.outputs.version }}
95-
body: |
96-
## What's Changed
97-
98-
${{ steps.changelog.outputs.changelog }}
99-
100-
## Installation
101-
102-
```toml
103-
[dependencies]
104-
solverforge-ui = "${{ steps.version.outputs.version }}"
105-
```
106-
draft: false
107-
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
94+
env:
95+
GITHUB_TOKEN: ${{ github.token }}
96+
run: |
97+
cat <<'EOF' > release-notes.md
98+
## What's Changed
99+
100+
${{ steps.changelog.outputs.changelog }}
101+
102+
## Installation
103+
104+
```toml
105+
[dependencies]
106+
solverforge-ui = "${{ steps.version.outputs.version }}"
107+
```
108+
EOF
109+
110+
release_args=(
111+
"v${{ steps.version.outputs.version }}"
112+
--target "${{ github.sha }}"
113+
--title "v${{ steps.version.outputs.version }}"
114+
--notes-file release-notes.md
115+
--verify-tag
116+
)
117+
118+
if [[ "${{ steps.version.outputs.version }}" == *-* ]]; then
119+
release_args+=(--prerelease)
120+
fi
121+
122+
gh release create "${release_args[@]}"

0 commit comments

Comments
 (0)