Skip to content

Commit efef238

Browse files
authored
Harden GitHub Actions workflows (#8476)
* Set permissions for the workflow jobs * Disable persisting credentials in most checkout actions * Correctly pass the token to the GitHub CLI * Pin used actions to specific commits * Explicitly set shell for scripts * Enable code scanning for GitHub Actions
1 parent 2dcdaa1 commit efef238

15 files changed

Lines changed: 255 additions & 124 deletions

‎.github/workflows/autoLabelDuplicate.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ on:
33
issue_comment:
44
types: [created]
55

6+
permissions: {}
7+
68
jobs:
79
test:
810
if: github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER'
911
runs-on: ubuntu-latest
12+
13+
permissions:
14+
issues: write
15+
1016
steps:
1117
- name: Check Comment Author
12-
uses: Amwam/issue-comment-action@v1.5.0
18+
uses: Amwam/issue-comment-action@b1d80926ace1eb32660ac96c7e89a16d4c36b749 #v1.5.0
1319
with:
1420
keywords: '["duplicate of #", "duplicate of https://github.com/FreeTubeApp/FreeTube/issues/", "duplicate of https://github.com/FreeTubeApp/FreeTube/pulls/"]'
1521
labels: '["U: duplicate"]'

‎.github/workflows/autoMerge.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212

1313
steps:
1414
- name: Auto Merge PR
15+
shell: bash
1516
env:
1617
GH_TOKEN: ${{ secrets.PUSH_TOKEN }}
1718
run: gh pr merge https://github.com/FreeTubeApp/FreeTube/pull/${{ github.event.pull_request.number }} --auto --squash

‎.github/workflows/build.yml‎

Lines changed: 54 additions & 42 deletions
Large diffs are not rendered by default.

‎.github/workflows/calibreapp-image-actions.yml‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,33 @@ on:
55
workflow_dispatch:
66
schedule:
77
- cron: '0 0 * * 0'
8+
9+
permissions: {}
10+
811
jobs:
912
build:
1013
name: calibreapp/image-actions
1114
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
1220
steps:
1321
- name: Checkout Repo
14-
uses: actions/checkout@v6
22+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
23+
with:
24+
persist-credentials: false
25+
1526
- name: Compress Images
1627
id: calibre
17-
uses: calibreapp/image-actions@main
28+
uses: calibreapp/image-actions@420075c115b26f8785e293c5bd5bef0911c506e5
1829
with:
1930
githubToken: ${{ secrets.GITHUB_TOKEN }}
2031
compressOnly: true
2132
- name: Create New Pull Request If Needed
2233
if: steps.calibre.outputs.markdown != ''
23-
uses: peter-evans/create-pull-request@v8
34+
uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725 #v8.0.0
2435
with:
2536
title: Compressed Images Nightly
2637
branch-suffix: timestamp

‎.github/workflows/codeql.yml‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ on:
99
schedule:
1010
- cron: '36 3 * * 5'
1111

12+
permissions: {}
13+
1214
jobs:
1315
analyze:
1416
name: Analyze
1517
runs-on: ubuntu-latest
18+
1619
permissions:
1720
actions: read
1821
contents: read
@@ -21,17 +24,19 @@ jobs:
2124
strategy:
2225
fail-fast: false
2326
matrix:
24-
language: [ 'javascript' ]
27+
language: [ 'actions', 'javascript' ]
2528
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
2629
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
2730

2831
steps:
2932
- name: Checkout repository
30-
uses: actions/checkout@v6
33+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
34+
with:
35+
persist-credentials: false
3136

3237
# Initializes the CodeQL tools for scanning.
3338
- name: Initialize CodeQL
34-
uses: github/codeql-action/init@v4
39+
uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
3540
with:
3641
languages: ${{ matrix.language }}
3742
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -44,7 +49,7 @@ jobs:
4449
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
4550
# If this step fails, then you should remove it and run the build manually (see below)
4651
- name: Autobuild
47-
uses: github/codeql-action/autobuild@v4
52+
uses: github/codeql-action/autobuild@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
4853

4954
# ℹ️ Command-line programs to run using the OS shell.
5055
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -57,6 +62,6 @@ jobs:
5762
# ./location_of_script_within_repo/buildscript.sh
5863

5964
- name: Perform CodeQL Analysis
60-
uses: github/codeql-action/analyze@v4
65+
uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
6166
with:
6267
category: "/language:${{matrix.language}}"

‎.github/workflows/conflicts.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ on:
88
pull_request_target:
99
types: [synchronize]
1010

11+
permissions: {}
12+
1113
jobs:
1214
main:
1315
runs-on: ubuntu-latest
16+
17+
permissions:
18+
pull-requests: write
19+
1420
steps:
1521
- name: check if prs are dirty
16-
uses: eps1lon/actions-label-merge-conflict@v3
22+
uses: eps1lon/actions-label-merge-conflict@1df065ebe6e3310545d4f4c4e862e43bdca146f0 #v3.0.3
1723
with:
1824
dirtyLabel: "PR: merge conflicts / rebase needed"
1925
removeOnDirtyLabel: "PR: waiting for review"

‎.github/workflows/flatpak.yml‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ on:
99
release:
1010
types: [published]
1111

12+
permissions: {}
13+
1214
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1315
jobs:
1416
build:
1517
runs-on: ubuntu-latest
1618

19+
permissions:
20+
contents: read
21+
1722
steps:
18-
- uses: actions/checkout@v6
23+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
1924
with:
2025
repository: flathub/io.freetubeapp.FreeTube
2126
token: ${{ secrets.FLATHUB_TOKEN }}
27+
persist-credentials: true
28+
2229
- name: Get Repo Release List
23-
uses: moustacheful/github-api-exec-action@v0
30+
uses: moustacheful/github-api-exec-action@2135aaccb1220f81e6fa4f14c90cc20efba069fe #v0
2431
id: list_results
2532
with:
2633
# Command to execute, (e.g: `pulls.create`), see https://octokit.github.io/rest.js/ for available commands
@@ -33,76 +40,83 @@ jobs:
3340
env:
3441
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3542
- name: Install xmlstarlet
43+
shell: bash
3644
run: sudo apt -y install xmlstarlet
3745
- name: Create Version Variable
38-
uses: bluwy/substitute-string-action@v3
46+
uses: bluwy/substitute-string-action@70ff0b17357670ffd3fee68e95b6de9963b66bad #v3.0.0
3947
id: sub
4048
with:
4149
_input-text: ${{ fromJson(steps.list_results.outputs.result)[0].tag_name }}
4250
-beta: ''
4351
v: ''
4452
- name: Create Release Branch
53+
shell: bash
4554
run: |
4655
git checkout -b release-v${{ steps.sub.outputs.result }}
4756
git push --set-upstream origin release-v${{ steps.sub.outputs.result }}
4857
- name: Download x64 Release
49-
uses: fabriciobastian/download-release-asset-action@v1.0.6
58+
uses: fabriciobastian/download-release-asset-action@35e62aa5a2fe4a6ec79004f6052918349013ae4f #v1.0.6
5059
with:
5160
version: v${{ steps.sub.outputs.result }}-beta
5261
repository: FreeTubeApp/FreeTube
5362
file: freetube-${{ steps.sub.outputs.result }}-beta-linux-x64-portable.zip
5463
- name: Download ARM Release
55-
uses: fabriciobastian/download-release-asset-action@v1.0.6
64+
uses: fabriciobastian/download-release-asset-action@35e62aa5a2fe4a6ec79004f6052918349013ae4f #v1.0.6
5665
with:
5766
version: v${{ steps.sub.outputs.result }}-beta
5867
repository: FreeTubeApp/FreeTube
5968
file: freetube-${{ steps.sub.outputs.result }}-beta-linux-arm64-portable.zip
6069
- name: Set x64 Hash Variable
6170
id: hash-x64
71+
shell: bash
6272
run: |
6373
echo 'HASH_X64<<EOF' >> $GITHUB_ENV
6474
sha256sum freetube-${{ steps.sub.outputs.result }}-beta-linux-x64-portable.zip | awk '{print $1}' >> $GITHUB_ENV
6575
echo 'EOF' >> $GITHUB_ENV
6676
- name: Set ARM Hash Variable
6777
id: hash-arm64
78+
shell: bash
6879
run: |
6980
echo 'HASH_ARM64<<EOF' >> $GITHUB_ENV
7081
sha256sum freetube-${{ steps.sub.outputs.result }}-beta-linux-arm64-portable.zip | awk '{print $1}' >> $GITHUB_ENV
7182
echo 'EOF' >> $GITHUB_ENV
7283
- name: Set Date Variable
7384
id: current-date
85+
shell: bash
7486
run: |
7587
echo 'CURRENT_DATE<<EOF' >> $GITHUB_ENV
7688
date +"%Y-%m-%d" >> $GITHUB_ENV
7789
echo 'EOF' >> $GITHUB_ENV
7890
- name: Update x64 File Location in yml File
79-
uses: mikefarah/yq@v4.50.1
91+
uses: mikefarah/yq@065b200af9851db0d5132f50bc10b1406ea5c0a8 #v4.50.1
8092
with:
8193
# The Command which should be run
8294
cmd: yq -i '.modules[0].sources[0].url = "https://github.com/FreeTubeApp/FreeTube/releases/download/v${{ steps.sub.outputs.result }}-beta/freetube-${{ steps.sub.outputs.result }}-beta-linux-x64-portable.zip"' io.freetubeapp.FreeTube.yml
8395
- name: Update x64 Hash in yml File
84-
uses: mikefarah/yq@v4.50.1
96+
uses: mikefarah/yq@065b200af9851db0d5132f50bc10b1406ea5c0a8 #v4.50.1
8597
with:
8698
# The Command which should be run
8799
cmd: yq -i '.modules[0].sources[0].sha256 = "${{ env.HASH_X64 }}"' io.freetubeapp.FreeTube.yml
88100
- name: Update ARM File Location in yml File
89-
uses: mikefarah/yq@v4.50.1
101+
uses: mikefarah/yq@065b200af9851db0d5132f50bc10b1406ea5c0a8 #v4.50.1
90102
with:
91103
# The Command which should be run
92104
cmd: yq -i '.modules[0].sources[1].url = "https://github.com/FreeTubeApp/FreeTube/releases/download/v${{ steps.sub.outputs.result }}-beta/freetube-${{ steps.sub.outputs.result }}-beta-linux-arm64-portable.zip"' io.freetubeapp.FreeTube.yml
93105
- name: Update ARM Hash in yml File
94-
uses: mikefarah/yq@v4.50.1
106+
uses: mikefarah/yq@065b200af9851db0d5132f50bc10b1406ea5c0a8 #v4.50.1
95107
with:
96108
# The Command which should be run
97109
cmd: yq -i '.modules[0].sources[1].sha256 = "${{ env.HASH_ARM64 }}"' io.freetubeapp.FreeTube.yml
98110
- name: Add Patch Notes to XML File
111+
shell: bash
99112
run: xmlstarlet ed -L -i /component/releases/release[1] -t elem -n releaseTMP -v "" -i //releaseTMP -t attr -n version -v "${{ steps.sub.outputs.result }} Beta" -i //releaseTMP -t attr -n date -v "${{ env.CURRENT_DATE }}" -s //releaseTMP -t elem -n url -v "" -s //releaseTMP/url -t text -n "" -v "https://github.com/FreeTubeApp/FreeTube/releases/tag/v${{ steps.sub.outputs.result }}-beta" -r //releaseTMP -v "release" io.freetubeapp.FreeTube.metainfo.xml
100113
- name: Remove Release Files
114+
shell: bash
101115
run: |
102116
rm freetube-${{ steps.sub.outputs.result }}-beta-linux-x64-portable.zip
103117
rm freetube-${{ steps.sub.outputs.result }}-beta-linux-arm64-portable.zip
104118
- name: Commit Files
105-
uses: stefanzweifel/git-auto-commit-action@v7
119+
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 #v7.1.0
106120
with:
107121
# Optional but recommended
108122
# Defaults to "Apply automatic changes"
@@ -115,8 +129,7 @@ jobs:
115129
# Optional: Disable dirty check and always try to create a commit and push
116130
skip_dirty_check: true
117131
- name: Create PR
118-
run: |
119-
echo ${{ secrets.FLATHUB_TOKEN }} >> auth.txt
120-
gh auth login --with-token < auth.txt
121-
rm auth.txt
122-
gh pr create --title "Release v${{ steps.sub.outputs.result }}" --body "This is an automated PR for the v${{ steps.sub.outputs.result }} release. This PR will be updated and merged once testing is complete."
132+
shell: bash
133+
env:
134+
GH_TOKEN: ${{ secrets.FLATHUB_TOKEN }}
135+
run: gh pr create --title "Release v${{ steps.sub.outputs.result }}" --body "This is an automated PR for the v${{ steps.sub.outputs.result }} release. This PR will be updated and merged once testing is complete."

‎.github/workflows/label-issue.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ on:
33
issues:
44
types: [opened]
55

6-
permissions:
7-
issues: write
8-
contents: read
6+
permissions: {}
97

108
jobs:
119
triage:
1210
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
issues: write
15+
1316
steps:
14-
- uses: github/issue-labeler@v3.4
17+
- uses: github/issue-labeler@c1b0f9f52a63158c4adc09425e858e87b32e9685 #v3.4
1518
with:
1619
configuration-path: .github/issue-labeler.yml
1720
enable-versioned-regex: 0

‎.github/workflows/label-pr.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ on:
33
pull_request_target:
44
types: [opened, reopened, ready_for_review]
55

6+
permissions: {}
7+
68
jobs:
79
triage:
810
permissions:
911
contents: read
1012
pull-requests: write
13+
1114
runs-on: ubuntu-latest
1215
if: ${{ !github.event.pull_request.draft }}
1316
steps:
14-
- uses: actions/labeler@v6
17+
- uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b #v6.0.1
1518
with:
1619
repo-token: "${{ secrets.GITHUB_TOKEN }}"
1720
configuration-path: .github/pr-labeler.yml

‎.github/workflows/linter.yml‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,39 @@ on:
88
pull_request:
99
branches: [ master, development, '**-RC' ]
1010

11+
permissions: {}
12+
1113
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1214
jobs:
1315
# This workflow contains a single job called "build"
1416
lint:
1517
# The type of runner that the job will run on
1618
runs-on: ubuntu-latest
1719

20+
permissions:
21+
actions: write
22+
contents: read
23+
1824
# Steps represent a sequence of tasks that will be executed as part of the job
1925
steps:
20-
- uses: actions/checkout@v6
26+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
27+
with:
28+
persist-credentials: false
29+
2130
- name: Use Node.js 24.x
22-
uses: actions/setup-node@v6
31+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f #v6.1.0
2332
with:
2433
node-version: 24.x
2534
cache: "yarn"
2635
- run: yarn run ci
36+
shell: bash
2737
env:
2838
ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
2939
- run: yarn run lint
40+
shell: bash
3041
# let's verify that webpack is able to package the project
3142
- run: yarn run pack
43+
shell: bash
3244
# verify that webpack is able to package the project using the web config
3345
- run: yarn run pack:web
46+
shell: bash

0 commit comments

Comments
 (0)