Skip to content

Commit

Permalink
chore(ci): use native permissions instead of LAVAMOAT_UPDATE_TOKEN
Browse files Browse the repository at this point in the history
the token is no longer necessary and permissions can be configured on
the workflow
  • Loading branch information
legobeat committed Jun 3, 2024
1 parent 71e4a5d commit 3b499f0
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions .github/workflows/update-lavamoat-policies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ jobs:
runs-on: ubuntu-latest
outputs:
IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }}
permissions:
actions: read
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Determine whether this PR is from a fork
id: is-fork
run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}

react-to-comment:
Expand All @@ -26,6 +30,10 @@ jobs:
needs: is-fork-pull-request
# Early exit if this is a fork, since later steps are skipped for forks
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
permissions:
actions: read
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -39,7 +47,7 @@ jobs:
-f content='+1'
env:
COMMENT_ID: ${{ github.event.comment.id }}
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}

prepare:
Expand All @@ -50,6 +58,10 @@ jobs:
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
outputs:
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
permissions:
actions: read
contents: write
pull-requests: write
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -61,7 +73,7 @@ jobs:
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Use Node.js
uses: actions/setup-node@v4
Expand All @@ -79,6 +91,10 @@ jobs:
runs-on: ubuntu-latest
needs:
- prepare
permissions:
actions: read
contents: read
pull-requests: read
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -90,7 +106,7 @@ jobs:
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down Expand Up @@ -118,6 +134,10 @@ jobs:
needs:
- prepare
- update-lavamoat-build-policy
permissions:
actions: read
contents: read
pull-requests: read
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -129,7 +149,7 @@ jobs:
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down Expand Up @@ -164,16 +184,20 @@ jobs:
- update-lavamoat-webapp-policy
# Ensure forks don't get access to the LavaMoat update token
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
permissions:
actions: read
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Use PAT to ensure that the commit later can trigger status check workflows
token: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
token: ${{ github.token }}
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Get commit SHA
id: commit-sha
Expand Down Expand Up @@ -243,7 +267,7 @@ jobs:
fi
env:
HAS_CHANGES: ${{ steps.policy-changes.outputs.HAS_CHANGES }}
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}

check-status:
Expand All @@ -265,17 +289,21 @@ jobs:
needs:
- is-fork-pull-request
- check-status
permissions:
actions: read
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
token: ${{ github.token }}
- name: Post comment if the update failed
run: |
passed="${{ needs.check-status.outputs.PASSED }}"
if [[ $passed != "true" ]]; then
gh pr comment "${PR_NUMBER}" --body "Policy update failed. You can [review the logs or retry the policy update here](${ACTION_RUN_URL})"
fi
env:
GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
ACTION_RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

0 comments on commit 3b499f0

Please sign in to comment.