Skip to content

Commit dbe96a3

Browse files
authored
Grant minimum permissions to github acitons workflow jobs (#682)
## Changes Granting the minimum necessary permissions is always a good practice. There might be cases where permissions are insufficient, but since errors are very clear, I believe we can add them when a failure occurs. After merging, I will change the default of the GITHUB_ACTIONS token from read + write to read only. Then, I will run as many workflows as possible (including publish) to verify their operation. reference: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token#overview
1 parent 98c8815 commit dbe96a3

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

.github/workflows/check-eol-newrelease.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
jobs:
1010
check-eol-newrelease:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
issues: write
15+
if: github.repository == 'line/line-bot-sdk-php'
1216
steps:
1317
- name: Check out code
1418
uses: actions/checkout@v4

.github/workflows/close-issue.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
permissions:
1212
issues: write
1313
pull-requests: write
14+
if: github.repository == 'line/line-bot-sdk-php'
1415
steps:
1516
- uses: actions/stale@v9
1617
with:

.github/workflows/create-draft-release.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ on:
2626
jobs:
2727
validate-input:
2828
runs-on: ubuntu-latest
29+
permissions: {}
2930
steps:
3031
- name: Validate Acknowledgement
3132
if: ${{ github.event.inputs.acknowledge_draft != 'Yes' }}
@@ -41,12 +42,13 @@ jobs:
4142
create-draft-release:
4243
runs-on: ubuntu-latest
4344
needs: validate-input
44-
45+
permissions:
46+
contents: write
4547
steps:
46-
- uses: actions/checkout@v4
48+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4749
- name: Fetch Latest Release
4850
id: get-latest-release
49-
uses: actions/github-script@v7
51+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
5052
with:
5153
script: |
5254
const latestRelease = await github.rest.repos.getLatestRelease({
@@ -62,7 +64,7 @@ jobs:
6264
6365
- name: Calculate New Version
6466
id: calculate-version
65-
uses: actions/github-script@v7
67+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
6668
with:
6769
script: |
6870
const latestTag = '${{ steps.get-latest-release.outputs.latest_tag }}';
@@ -83,7 +85,7 @@ jobs:
8385
8486
- name: Generate Release Notes
8587
id: generate-release-notes
86-
uses: actions/github-script@v7
88+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
8789
with:
8890
script: |
8991
const { data: releaseNotes } = await github.rest.repos.generateReleaseNotes({

.github/workflows/generate-code.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
tests:
1313
name: Generate OpenAPI based code
1414
runs-on: ubuntu-latest
15-
15+
permissions:
16+
contents: write
17+
pull-requests: write
1618
steps:
1719
# Setup
1820
- uses: actions/checkout@v4

.github/workflows/php-checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
tests:
1010
name: Run checks on PHP ${{ matrix.php }}
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
1214
strategy:
1315
fail-fast: false
1416
matrix:

.github/workflows/release.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@ on:
55
types: [ published ]
66
workflow_dispatch:
77

8-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
9-
permissions:
10-
contents: read
11-
pages: write
12-
id-token: write
13-
14-
158
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
169
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
1710
concurrency:
1811
group: "pages"
1912
cancel-in-progress: false
2013

21-
2214
jobs:
2315
# Single deploy job since we're just deploying
2416
deploy:
2517
environment:
2618
name: github-pages
2719
url: ${{ steps.deployment.outputs.page_url }}
2820
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pages: write
24+
id-token: write
25+
issues: write
2926
steps:
3027
- name: Checkout
3128
uses: actions/checkout@v4
@@ -38,3 +35,21 @@ jobs:
3835
- name: Deploy to GitHub Pages
3936
id: deployment
4037
uses: actions/deploy-pages@v4
38+
39+
- name: Create GitHub Issue on Failure
40+
if: failure()
41+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
42+
with:
43+
script: |
44+
const { owner, repo } = context.repo;
45+
const issueTitle = `deploy-page job failed`;
46+
const issueBody = `The deploy-page job failed. Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.`;
47+
const assignees = [context.actor];
48+
49+
await github.rest.issues.create({
50+
owner,
51+
repo,
52+
title: issueTitle,
53+
body: issueBody,
54+
assignees
55+
});

0 commit comments

Comments
 (0)