Skip to content

Commit fca786d

Browse files
committed
Harden GitHub workflows against action supply-chain risk
1 parent 84130bb commit fca786d

File tree

3 files changed

+57
-49
lines changed

3 files changed

+57
-49
lines changed

.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: 43 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

@@ -56,9 +53,14 @@ jobs:
5653
needs: [test]
5754

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

0 commit comments

Comments
 (0)