Skip to content

Commit 4608198

Browse files
[9.x] Harden GitHub Actions workflows (#819)
1 parent b0e191a commit 4608198

6 files changed

Lines changed: 105 additions & 18 deletions

File tree

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ updates:
88
github-actions:
99
patterns:
1010
- "*"
11+
# Supply chain attack mitigation: wait 7 days before updating
12+
# to allow community detection of compromised releases
13+
cooldown:
14+
default-days: 7

.github/workflows/code-style-lint.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ on:
55
paths:
66
- '**.php'
77

8+
permissions: {}
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
814
jobs:
915
lint-code-styling:
16+
name: Lint code styling
1017
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
1120

1221
steps:
1322
- name: Checkout code
1423
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
with:
25+
persist-credentials: false
1526

1627
- name: Check PHP code style issues
1728
uses: aglipanci/laravel-pint-action@36de00d5f5a8a4e12d443e01671daa12a18f4c79 # 2.6

.github/workflows/pr-title.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ on:
44
pull_request:
55
types: [opened, edited, synchronize, reopened]
66

7+
permissions: {}
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
713
jobs:
814
pr-title:
15+
name: Validate PR title
916
runs-on: ubuntu-latest
17+
permissions: {}
1018
steps:
11-
- uses: deepakputhraya/action-pr-title@077bddd7bdabd0d2b1b25ed0754c7e62e184d7ee # master
19+
- name: Check PR title format
20+
uses: deepakputhraya/action-pr-title@3864bebc79c5f829d25dd42d3c6579d040b0ef16 # v1.0.2
1221
with:
1322
regex: '^\[\d+\.x\]\s'

.github/workflows/release.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@ on:
1212
tags:
1313
- "v*"
1414

15+
permissions: {}
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
1521
jobs:
1622
release:
1723
name: Prepare & Create Release
1824
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write # Create releases and upload assets
27+
issues: write # Comment on related issues
28+
pull-requests: write # Comment on related PRs
1929
steps:
2030
- name: Checkout code
2131
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32+
with:
33+
persist-credentials: false
2234

2335
- name: Setup PHP
2436
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2
@@ -45,26 +57,29 @@ jobs:
4557
with:
4658
version: ${{ github.ref }}
4759

48-
- name: Create release
49-
id: create_release
50-
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1
60+
- name: Determine prerelease status
61+
id: prerelease
5162
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
with:
54-
tag_name: ${{ github.ref }}
55-
release_name: ${{ github.ref }}
56-
body: ${{ steps.changelog.outputs.text }}
57-
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
63+
REF: ${{ github.ref }}
64+
run: |
65+
if [[ "$REF" == *"-alpha"* ]] || [[ "$REF" == *"-beta"* ]]; then
66+
echo "flag=--prerelease" >> $GITHUB_OUTPUT
67+
else
68+
echo "flag=" >> $GITHUB_OUTPUT
69+
fi
5870
59-
- name: Upload zip to release
60-
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1.0.2
71+
- name: Create release
6172
env:
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63-
with:
64-
upload_url: ${{ steps.create_release.outputs.upload_url }}
65-
asset_path: ./dist.tar.gz
66-
asset_name: dist.tar.gz
67-
asset_content_type: application/tar+gz
73+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
TAG_NAME: ${{ github.ref_name }}
75+
CHANGELOG: ${{ steps.changelog.outputs.text }}
76+
PRERELEASE_FLAG: ${{ steps.prerelease.outputs.flag }}
77+
run: |
78+
gh release create "$TAG_NAME" \
79+
--title "$TAG_NAME" \
80+
--notes "$CHANGELOG" \
81+
$PRERELEASE_FLAG \
82+
./dist.tar.gz
6883
6984
- name: Comment on related issues
7085
uses: duncanmcclean/post-release-comments@ee2d062e73bd6f0898f36ed892953ed88134cc19 # v1.0.6

.github/workflows/tests.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ on:
77
- '*.x'
88
pull_request:
99

10+
permissions: {}
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1016
jobs:
1117
php_tests:
1218
if: "!contains(github.event.head_commit.message, 'changelog')"
1319

1420
runs-on: ${{ matrix.os }}
21+
permissions:
22+
contents: read
1523

1624
strategy:
1725
matrix:
@@ -30,6 +38,8 @@ jobs:
3038
steps:
3139
- name: Checkout code
3240
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
41+
with:
42+
persist-credentials: false
3343

3444
- name: Setup PHP
3545
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2
@@ -38,6 +48,7 @@ jobs:
3848
extensions: fileinfo, exif, gd, pdo, sqlite, pdo_sqlite, intl
3949

4050
- name: Install dependencies
51+
# zizmor: ignore[template-injection] - matrix values are defined in this file, not attacker-controlled
4152
run: |
4253
composer require "illuminate/contracts:${{ matrix.laravel }}" --no-interaction --no-update
4354
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest

.github/workflows/zizmor.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: GitHub Actions Security Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- 9.x
7+
paths:
8+
- '.github/**.yml'
9+
- '.github/**.yaml'
10+
pull_request:
11+
paths:
12+
- '.github/**.yml'
13+
- '.github/**.yaml'
14+
15+
permissions: {}
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
zizmor:
23+
name: zizmor
24+
runs-on: ubuntu-latest
25+
permissions: {}
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
persist-credentials: false
31+
32+
- name: Run zizmor
33+
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
34+
with:
35+
advanced-security: false
36+
annotations: true
37+
persona: pedantic

0 commit comments

Comments
 (0)