diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 7f0fb9e..c28b17a 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -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 }} diff --git a/README.md b/README.md index 3005147..8700f0a 100644 --- a/README.md +++ b/README.md @@ -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 |
${{ github.action_path }}/repo
| +The `job-context` action does not support any inputs. ## Outputs diff --git a/action.yaml b/action.yaml index a26966f..8262905 100644 --- a/action.yaml +++ b/action.yaml @@ -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. @@ -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: | @@ -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 @@ -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) }}