Skip to content

Commit

Permalink
Support nested composite actions
Browse files Browse the repository at this point in the history
To reference metadata about composite actions, GitHub Actions provides
the `github.action_` context, including `github.action_path`,
`github.action_ref`, and `github.action_repository`.

GitHub Actions supports nested composite actions with a recursion limit
of 9 (9 nested composite actions). Unfortunately `github.action_` values
are not propagated correctly when running nested composite actions.
This is a bug in the GitHub Actions runner.

The suggested workaround is to use inputs to set the correct values.
This commit will implement the suggested workaround.

https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#github-context
actions/runner#2473 (comment)
pypa#299
  • Loading branch information
br3ndonland committed Nov 12, 2024
1 parent 15c56db commit 89eff37
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ inputs:
Only works with PyPI and TestPyPI via Trusted Publishing.
required: false
default: 'true'
action_path:
description: >-
[EXPERIMENTAL]
Set action path to work around bug in nested composite actions
https://github.com/actions/runner/issues/2473
required: false
default: ${{ github.action_path }}
action_repository:
description: >-
[EXPERIMENTAL]
Set action repository to work around bug in nested composite actions
https://github.com/actions/runner/issues/2473
required: false
default: ${{ github.action_repository }}
action_ref:
description: >-
[EXPERIMENTAL]
Set action ref to work around bug in nested composite actions
https://github.com/actions/runner/issues/2473
required: false
default: ${{ github.action_ref }}
branding:
color: yellow
icon: upload-cloud
Expand Down Expand Up @@ -116,17 +137,21 @@ runs:
run: |
# Set repo and ref from which to run Docker container action
# to handle cases in which `github.action_` context is not set
# or set properly for nested composite actions
# https://github.com/actions/runner/issues/2473
ACTION_PATH=${{ env.ACTION_PATH || github.workspace }}
REF=${{ env.ACTION_REF || env.PR_REF || github.ref_name }}
REPO=${{ env.ACTION_REPO || env.PR_REPO || github.repository }}
REPO_ID=${{ env.PR_REPO_ID || github.repository_id }}
echo "action-path=$ACTION_PATH" >>"$GITHUB_OUTPUT"
echo "ref=$REF" >>"$GITHUB_OUTPUT"
echo "repo=$REPO" >>"$GITHUB_OUTPUT"
echo "repo-id=$REPO_ID" >>"$GITHUB_OUTPUT"
shell: bash
env:
ACTION_REF: ${{ github.action_ref }}
ACTION_REPO: ${{ github.action_repository }}
ACTION_PATH: ${{ inputs.action_path }}
ACTION_REF: ${{ inputs.action_ref }}
ACTION_REPO: ${{ inputs.action_repository }}
PR_REF: ${{ github.event.pull_request.head.ref }}
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_REPO_ID: ${{ github.event.pull_request.base.repo.id }}
Expand All @@ -149,8 +174,9 @@ runs:
steps.pre-installed-python.outputs.python-path == ''
&& steps.new-python.outputs.python-path
|| steps.pre-installed-python.outputs.python-path
}} '${{ github.action_path }}/create-docker-action.py'
}} '${{ env.ACTION_PATH }}/create-docker-action.py'
env:
ACTION_PATH: ${{ steps.set-repo-and-ref.outputs.action-path }}
REF: ${{ steps.set-repo-and-ref.outputs.ref }}
REPO: ${{ steps.set-repo-and-ref.outputs.repo }}
REPO_ID: ${{ steps.set-repo-and-ref.outputs.repo-id }}
Expand Down

0 comments on commit 89eff37

Please sign in to comment.