Skip to content

Commit 3bc24ad

Browse files
authored
Merge pull request #2159 from jku/permissions-tweaks
Github workflows: Permissions tweaks
2 parents 5a4c7ad + b002860 commit 3bc24ad

5 files changed

Lines changed: 40 additions & 16 deletions

File tree

.github/workflows/_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ on:
22
workflow_call:
33
# Permissions inherited from caller workflow
44

5+
permissions: {}
56

67
jobs:
78
tests:

.github/workflows/cd.yml

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ on:
66
tags:
77
- v*
88

9-
permissions:
10-
contents: write
9+
permissions: {}
1110

1211
jobs:
1312
test:
@@ -17,8 +16,6 @@ jobs:
1716
name: Build
1817
runs-on: ubuntu-latest
1918
needs: test
20-
outputs:
21-
release_id: ${{ steps.gh-release.outputs.id }}
2219
steps:
2320
- name: Checkout release tag
2421
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
@@ -36,6 +33,30 @@ jobs:
3633
- name: Build binary wheel and source tarball
3734
run: python3 -m build --sdist --wheel --outdir dist/ .
3835

36+
- name: Store build artifacts
37+
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
38+
# NOTE: The GitHub release page contains the release artifacts too, but using
39+
# GitHub upload/download actions seems robuster: there is no need to compute
40+
# download URLs and tampering with artifacts between jobs is more limited.
41+
with:
42+
name: build-artifacts
43+
path: dist
44+
45+
candidate_release:
46+
name: Release candidate on Github for review
47+
runs-on: ubuntu-latest
48+
needs: build
49+
permissions:
50+
contents: write # to modify GitHub releases
51+
outputs:
52+
release_id: ${{ steps.gh-release.outputs.id }}
53+
steps:
54+
- name: Fetch build artifacts
55+
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
56+
with:
57+
name: build-artifacts
58+
path: dist
59+
3960
- id: gh-release
4061
name: Publish GitHub release candidate
4162
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
@@ -45,20 +66,14 @@ jobs:
4566
body: "Release waiting for review..."
4667
files: dist/*
4768

48-
- name: Store build artifacts
49-
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
50-
# NOTE: The GitHub release page contains the release artifacts too, but using
51-
# GitHub upload/download actions seems robuster: there is no need to compute
52-
# download URLs and tampering with artifacts between jobs is more limited.
53-
with:
54-
name: build-artifacts
55-
path: dist
5669

5770
release:
5871
name: Release
5972
runs-on: ubuntu-latest
60-
needs: build
73+
needs: candidate_release
6174
environment: release
75+
permissions:
76+
contents: write # to modify GitHub releases
6277
steps:
6378
- name: Fetch build artifacts
6479
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
@@ -67,6 +82,8 @@ jobs:
6782
path: dist
6883

6984
- name: Publish binary wheel and source tarball on PyPI
85+
# Only attempt pypi upload in upstream repository
86+
if: github.repository == 'theupdateframework/python-tuf'
7087
uses: pypa/gh-action-pypi-publish@37f50c210e3d2f9450da2cd423303d6a14a6e29f
7188
with:
7289
user: __token__
@@ -79,7 +96,7 @@ jobs:
7996
await github.rest.repos.updateRelease({
8097
owner: context.repo.owner,
8198
repo: context.repo.repo,
82-
release_id: '${{ needs.build.outputs.release_id }}',
99+
release_id: '${{ needs.candidate_release.outputs.release_id }}',
83100
name: '${{ github.ref_name }}',
84101
body: 'See [CHANGELOG.md](https://github.com/' +
85102
context.repo.owner + '/' + context.repo.repo +

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ on:
88
pull_request:
99
workflow_dispatch:
1010

11-
permissions:
12-
contents: read
11+
permissions: {}
1312

1413
jobs:
1514
test:

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches: [ develop ]
88
schedule:
99
- cron: '30 0 * * 2'
10+
workflow_dispatch:
11+
12+
permissions: {}
1013

1114
jobs:
1215
analyze:

.github/workflows/specification-version-check.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ on:
22
schedule:
33
- cron: "0 13 * * *"
44
workflow_dispatch:
5+
56
name: Specification version check
7+
8+
permissions: {}
9+
610
jobs:
711
# Get the version of the TUF specification the project states it supports
812
get-supported-tuf-version:

0 commit comments

Comments
 (0)