Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for use within other actions #7

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,26 @@ jobs:
[[ -z "${job_id}" ]] || exit 1
env:
job_id: ${{ steps.job.outputs.id }}

# Using `job-context` within another action requires the path to be set correct to be able to
# clone the workflow repository.
test-embedded:
name: Embedded
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- id: dynamic-job
uses: jenseng/dynamic-uses@02f544690a931f3967153cd5f14679cfeb61f830 # v1
with:
uses: beacon-biosignals/job-context@${{ github.event.pull_request.head.sha || github.sha }} # Always use HEAD commit
- name: Test job name
run: '[[ "${output}" == "${expected}" ]] || exit 1'
env:
output: ${{ fromJSON(steps.dynamic-job.outputs.outputs).name }}
expected: Embedded
- name: Test job ID
run: |
[[ "${job_id}" =~ ^[0-9]+$ ]] || exit 1
env:
job_id: ${{ fromJSON(steps.dynamic-job.outputs.outputs).id }}
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ jobs:

## Inputs

The `job-context` action supports the following inputs:

| Name | Description | Required | Example |
|:-----------------|:------------|:---------|:--------|
| `path` | The path to the cloned repo containing the workflow. Should only be needed by other GHAs using this action. | No | <pre><code>${{ github.action_path }}/repo</code></pre> |
The `job-context` action does not support any inputs.

## Outputs

Expand Down
24 changes: 12 additions & 12 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ description: Provides additional context for the currently running job
branding:
icon: box
color: black
inputs:
path:
description: >-
The path to the cloned repo containing the workflow. Should only be needed by other
GHAs using this action.
type: string
default: ""
required: false
outputs:
name:
description: The rendered job name.
Expand All @@ -24,12 +16,13 @@ outputs:
runs:
using: composite
steps:
# In order to determine the job name we'll extract the non-rendered job name from the
# workflow and then evaulate any expressions contained within.
# In order to determine the job name we'll extract the non-rendered job name from the workflow and then evaulate
# any expressions contained within. Using `action/checkout` requires that we set the path under `$GITHUB_WORSPACE`.
- uses: actions/checkout@v4
id: checkout
with:
ref: ${{ github.workflow_sha }}
path: ${{ inputs.path || format('{0}/repo', github.action_path) }}
path: ${{ format('{0}/.job-context-repo', github.workspace) }}
- id: workflow
shell: bash
run: |
Expand All @@ -42,7 +35,7 @@ runs:
job_name_template="$(job_key="${job_key}" yq '.jobs[env(job_key)] | select(has("name")).name | select(. != null)' "${repo_path}/${workflow_path:?}")"
echo "name-template=${job_name_template}" | tee -a "$GITHUB_OUTPUT"
env:
repo_path: ${{ inputs.path || format('{0}/repo', github.action_path) }}
repo_path: ${{ format('{0}/.job-context-repo', github.workspace) }}
workflow_ref: ${{ github.workflow_ref }}
job_key: ${{ github.job }} # User supplied job key cannot be allowed as we cannot properly render `matrix` expressions later
- id: render
Expand Down Expand Up @@ -105,6 +98,13 @@ runs:
fi
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run_id: ${{ github.run_id }}
run_attempt: ${{ github.run_attempt }}
job_name: ${{ steps.render.outputs.name }}
- name: Cleanup
if: ${{ always() && steps.checkout.output == 'success' }}
shell: bash
run: rm -rf "${repo_path:?}"
env:
repo_path: ${{ format('{0}/.job-context-repo', github.workspace) }}
Loading