Skip to content

Commit a83efef

Browse files
committed
Fix workflows for reducing risks
1 parent 6f074ee commit a83efef

4 files changed

Lines changed: 55 additions & 14 deletions

File tree

.github/workflows/create-release.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ on:
44
push:
55
tags:
66
- '*'
7+
permissions: {}
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
711

812
jobs:
913
release:
14+
name: Create GitHub Release
1015
runs-on: ubuntu-latest
1116
permissions:
12-
contents: write
17+
contents: write # for gh release create
1318

1419
steps:
1520
- name: Checkout repository
1621
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
22+
with:
23+
persist-credentials: false
1724

1825
- name: Extract release notes from CHANGELOG.md
1926
id: changelog
@@ -31,10 +38,16 @@ jobs:
3138
echo "EOF" >> "$GITHUB_ENV"
3239
fi
3340
34-
- name: Create GitHub Release
35-
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
41+
- name: Create Release
3642
if: ${{ startsWith(github.ref, 'refs/tags/') }}
37-
with:
38-
tag_name: ${{ env.TAG_NAME }}
39-
name: ${{ env.TAG_NAME }}
40-
body: ${{ env.RELEASE_BODY }}
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
TAG_NAME: ${{ env.TAG_NAME }}
46+
RELEASE_BODY: ${{ env.RELEASE_BODY }}
47+
run: |
48+
if [ -n "$RELEASE_BODY" ]; then
49+
printf '%s\n' "$RELEASE_BODY" > release-notes.md
50+
gh release create "$TAG_NAME" --title "$TAG_NAME" --notes-file release-notes.md
51+
else
52+
gh release create "$TAG_NAME" --title "$TAG_NAME"
53+
fi

.github/workflows/main-ci.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
name: Main CI
22
on:
33
push:
4+
permissions: {}
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: false
48

59
jobs:
610
get-vars:
711
uses: ./.github/workflows/nodevars.yml
812

913
main:
14+
name: Lint and Test
1015
needs: get-vars
1116
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1219
steps:
1320
- name: Checkout
1421
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
22+
with:
23+
persist-credentials: false
1524
- name: Setup node
1625
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
1726
with:
1827
node-version: ${{ needs.get-vars.outputs.node-version }}
1928
cache: npm
2029
- name: Setup npm
21-
run: npm i -g npm@${{ needs.get-vars.outputs.npm-version }}
30+
run: npm i -g npm@${NPM_VERSION}
31+
env:
32+
NPM_VERSION: ${{ needs.get-vars.outputs.npm-version }}
2233
- name: Cache node modules
2334
id: node_modules_cache
2435
uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3.5.0
@@ -37,13 +48,16 @@ jobs:
3748
- name: Test
3849
run: npm run test
3950
windows-test:
51+
name: Test using Windows environment
4052
needs: get-vars
4153
runs-on: windows-latest
4254
env:
4355
TEST_IGNORE_256_ICON: 1
4456
steps:
4557
- name: Checkout
4658
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
59+
with:
60+
persist-credentials: false
4761
- name: Setup node
4862
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
4963
with:
@@ -60,7 +74,9 @@ jobs:
6074
- name: Install
6175
if: steps.node_modules_cache.outputs.cache-hit != 'true'
6276
# use npx instead of installing npm globally to avoid permission error
63-
run: npx -y npm@${{ needs.get-vars.outputs.npm-version }} ci
77+
run: npx -y npm@${NPM_VERSION} ci
78+
env:
79+
NPM_VERSION: ${{ needs.get-vars.outputs.npm-version }}
6480
- name: Test (x86)
6581
# use normal npm (which should not affect to the test)
6682
run: npm run test:win-x86

.github/workflows/nodevars.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ on:
99
npm-version:
1010
description: 'Common NPM version'
1111
value: ${{ jobs.export.outputs.npm-version }}
12-
1312
env:
1413
NODE_VERSION: 20.19.5
1514
NPM_VERSION: 11.12.1
15+
permissions: {}
1616

1717
jobs:
1818
export:
19+
name: Output version variables
1920
runs-on: ubuntu-latest
2021
outputs:
2122
node-version: ${{ steps.setver.outputs.node_version }}
2223
npm-version: ${{ steps.setver.outputs.npm_version }}
2324
steps:
2425
- id: setver
26+
name: Output variables
2527
run: |
26-
echo "node_version=${{ env.NODE_VERSION }}" >> $GITHUB_OUTPUT
27-
echo "npm_version=${{ env.NPM_VERSION }}" >> $GITHUB_OUTPUT
28+
echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT
29+
echo "npm_version=${NPM_VERSION}" >> $GITHUB_OUTPUT

.github/workflows/publish.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,39 @@ on:
33
push:
44
tags:
55
- 'v*.*.*'
6+
permissions: {}
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
610

711
jobs:
812
get-vars:
913
uses: ./.github/workflows/nodevars.yml
1014

1115
main:
16+
name: Publish package
1217
needs: get-vars
1318
runs-on: ubuntu-latest
1419
permissions:
1520
contents: read
16-
id-token: write
21+
id-token: write # for npm publish --provenance
1722
environment:
1823
name: Publish
1924
steps:
2025
- name: Checkout
2126
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
27+
with:
28+
persist-credentials: false
2229
- name: Setup node
2330
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
2431
with:
2532
node-version: ${{ needs.get-vars.outputs.node-version }}
2633
registry-url: 'https://registry.npmjs.org'
34+
package-manager-cache: false
2735
- name: Setup npm
28-
run: npm i -g npm@${{ needs.get-vars.outputs.npm-version }}
36+
run: npm i -g npm@${NPM_VERSION}
37+
env:
38+
NPM_VERSION: ${{ needs.get-vars.outputs.npm-version }}
2939
- name: Install
3040
run: npm ci
3141
- name: Build

0 commit comments

Comments
 (0)