From 2d1c67eeef5d4c8ec952c08744029f50195b381f Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 8 Oct 2024 21:39:32 -0500 Subject: [PATCH 1/3] Improve support for use within other actions --- .github/workflows/integration-tests.yaml | 23 +++++++++++++++++++++++ README.md | 6 +----- action.yaml | 23 +++++++++++------------ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 7f0fb9e..7babc9b 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@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..c647e43 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 @@ -108,3 +101,9 @@ runs: 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) }} From 3a72e292f82a3dc4c3701f6c78863f3627bb7ddf Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 8 Oct 2024 21:43:11 -0500 Subject: [PATCH 2/3] fixup! Improve support for use within other actions --- action.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yaml b/action.yaml index c647e43..8262905 100644 --- a/action.yaml +++ b/action.yaml @@ -98,6 +98,7 @@ 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 }} From feb19068daba58b3ba472ad3821c898db927c4a2 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Wed, 9 Oct 2024 09:02:35 -0500 Subject: [PATCH 3/3] Use commit SHA for `jenseng/dynamic-uses` Co-authored-by: Mkrtich Vatinyan --- .github/workflows/integration-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 7babc9b..c28b17a 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -229,7 +229,7 @@ jobs: contents: read steps: - id: dynamic-job - uses: jenseng/dynamic-uses@v1 + 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