Is it possible to evaluate permissions
after if
?
#63736
-
Select Topic AreaQuestion BodyConsider the following simplified use case: $ cat .github/workflows/trigger.yml name: Trigger
on:
workflow_dispatch:
jobs:
job:
uses: ./.github/workflows/deploy.yml
with:
registry: dockerhub $ cat .github/workflows/deploy.yml on:
workflow_call:
inputs:
registry:
type: string
jobs:
ghcr:
if: inputs.registry == 'ghcr'
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- run: echo Deploy to GHCR
dockerhub:
if: inputs.registry != 'ghcr'
runs-on: ubuntu-latest
steps:
- run: echo Deploy to Docker Hub Running the workflow Trigger results in an error message:
I didn't expect this because the condition for job |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The problem does not occur when workflow permissions are changed from default ("Read repository contents and packages permissions") to read/write in the repository settings. So apparently the permission elevation of the |
Beta Was this translation helpful? Give feedback.
-
GitHub Support pointed out that it makes a difference whether permissions are defined in the calling workflow or the called workflow. When defined in the caller workflow ( Albeit that, the following trigger workflow fails when run with default inputs: name: Trigger
on:
workflow_dispatch:
inputs:
registry:
type: string
default: dockerhub
jobs:
ghcr:
if: inputs.registry == 'ghcr'
permissions:
packages: write
uses: ./.github/workflows/deploy.yml
with:
registry: ${{ inputs.registry }}
dockerhub:
if: inputs.registry != 'ghcr'
uses: ./.github/workflows/deploy.yml
with:
registry: ${{ inputs.registry }} Error message:
|
Beta Was this translation helpful? Give feedback.
-
Quote from a discussion with the GitHub Support:
That explains the behavior. It would be nice if this could be changed so that permissions are evaluated after |
Beta Was this translation helpful? Give feedback.
Quote from a discussion with the GitHub Support:
That explains the behavior.
It would be nice if this could be changed so that permissions are evaluated after
if
conditions.