From 4f498a549afee46cc86003d0fcfcbef900a31361 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:19:57 +0200 Subject: [PATCH 01/23] Add check-dependent-jobs action --- .../workflows/test-check-dependent-jobs.yml | 43 ++++++++++++++++ check-dependent-jobs/README.md | 49 +++++++++++++++++++ check-dependent-jobs/action.yml | 28 +++++++++++ 3 files changed, 120 insertions(+) create mode 100644 .github/workflows/test-check-dependent-jobs.yml create mode 100644 check-dependent-jobs/README.md create mode 100644 check-dependent-jobs/action.yml diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml new file mode 100644 index 0000000..34cbf6e --- /dev/null +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -0,0 +1,43 @@ +name: test-check-dependent-jobs + +on: + pull_request: + branches: + - main + paths: + - '.github/workflows/test-check-dependent-jobs.yml' + - 'oblt-cli/test-check-dependent-jobs/**' + push: + branches: + - main + paths: + - '.github/workflows/test-check-dependent-jobs.yml' + - 'oblt-cli/test-check-dependent-jobs/**' + +permissions: + contents: read + +jobs: + test-a: + runs-on: ubuntu-latest + steps: + - run: exit 0 + test-b: + continue-on-error: true + runs-on: ubuntu-latest + steps: + - run: exit 1 + test: + runs-on: ubuntu-latest + needs: + - test-a + - test-b + steps: + - uses: actions/checkout@v4 + - uses: ./test-check-dependent-jobs + id: check + with: + needs: ${{ toJSON(needs) }} + - name: assert + run: | + test "${{ steps.check.outputs.is-success }}" = "false" diff --git a/check-dependent-jobs/README.md b/check-dependent-jobs/README.md new file mode 100644 index 0000000..11d43af --- /dev/null +++ b/check-dependent-jobs/README.md @@ -0,0 +1,49 @@ +## About + +Evaluates the combined the status results of the provided needs context. +This is useful for creating a single status check. + +That status check can then be set as required status check, or it can be used +in combination with the `notify-built-status` action. + +## Inputs + +Following inputs can be used as `step.with` keys + +| Name | Type | Default | Description | +|--------------|---------|-----------------------------|----------------------------------| +| `needs` | String | | JSON string of the needs context | + +## Outputs + +| Name | Type | Description | +|--------------|---------|------------------------------------| +| `is-success` | Boolean | If all jobs are successful or not. | +| `status` | String | `success` or `failure` | + + +## Usage + +```yaml +jobs: + job-a: + runs-on: ubuntu-latest + steps: + - run: exit 1; + job-b: + runs-on: ubuntu-latest + steps: + - run: exit 0; + job-c: + if: always() + runs-on: ubuntu-latest + needs: + - job-a + - job-b + steps: + - id: check + uses: elastic/oblt-actions/check-dependent-jobs@v1 + with: + needs: ${{ toJSON(needs) }} + - run: ${{ steps.check.outputs.is-success }} # should exit with 1 or 0. +``` diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml new file mode 100644 index 0000000..dc8749d --- /dev/null +++ b/check-dependent-jobs/action.yml @@ -0,0 +1,28 @@ +name: check-dependent-jobs +description: | + Evaluates the combined the status results of the provided needs context. +inputs: + needs: + required: true + description: needs context as JSON string +outputs: + isSuccess: + description: The evaluated result of all provided jobs in the needs context. + value: ${{ steps.test.outputs.isSuccess }} + status: + description: One of success or failure. + value: ${{ steps.test.outputs.status }} +runs: + using: composite + steps: + - id: test + run: | + RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') + echo "isSuccess=${RESULT}" >> $GITHUB_OUTPUT + if [[ $RESULT == true ]]; then + STATUS=success + else + STATUS=failure + fi + echo "status=${STATUS}" >> $GITHUB_OUTPUT + shell: bash From db532873b79ba82cec156066e0fe2e65547f87fb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:21:36 +0200 Subject: [PATCH 02/23] fix --- .github/workflows/test-check-dependent-jobs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 34cbf6e..726e2a5 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -34,7 +34,7 @@ jobs: - test-b steps: - uses: actions/checkout@v4 - - uses: ./test-check-dependent-jobs + - uses: ./check-dependent-jobs id: check with: needs: ${{ toJSON(needs) }} From 55b812682cb66e872718c1188fce4e52825e621f Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:22:51 +0200 Subject: [PATCH 03/23] fix --- check-dependent-jobs/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index dc8749d..385fdb8 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -6,9 +6,9 @@ inputs: required: true description: needs context as JSON string outputs: - isSuccess: + is-success: description: The evaluated result of all provided jobs in the needs context. - value: ${{ steps.test.outputs.isSuccess }} + value: ${{ steps.test.outputs.is-success }} status: description: One of success or failure. value: ${{ steps.test.outputs.status }} @@ -18,7 +18,7 @@ runs: - id: test run: | RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') - echo "isSuccess=${RESULT}" >> $GITHUB_OUTPUT + echo "is-success=${RESULT}" >> $GITHUB_OUTPUT if [[ $RESULT == true ]]; then STATUS=success else From 86bc7510871479d441c4425612f75d64ae290108 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:23:55 +0200 Subject: [PATCH 04/23] test --- .github/workflows/test-check-dependent-jobs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 726e2a5..b666fc4 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -23,7 +23,6 @@ jobs: steps: - run: exit 0 test-b: - continue-on-error: true runs-on: ubuntu-latest steps: - run: exit 1 From 1c69834e6d657bd7c2e55acc2d3d2636794a33b4 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:24:48 +0200 Subject: [PATCH 05/23] fix --- .github/workflows/test-check-dependent-jobs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index b666fc4..08282a6 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -27,6 +27,7 @@ jobs: steps: - run: exit 1 test: + if: always() runs-on: ubuntu-latest needs: - test-a From a2c7d6b7f5235f8e351a9c91045bbe21811e709c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:25:52 +0200 Subject: [PATCH 06/23] Add debug --- check-dependent-jobs/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index 385fdb8..8e1d5fd 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -17,6 +17,8 @@ runs: steps: - id: test run: | + echo "##[debug] needs: ${{ inputs.needs }}" + RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') echo "is-success=${RESULT}" >> $GITHUB_OUTPUT if [[ $RESULT == true ]]; then From 3f0a844082a05c366e86bca40ac8c17e43081495 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:28:51 +0200 Subject: [PATCH 07/23] test --- .github/workflows/test-check-dependent-jobs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 08282a6..2396f54 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -23,6 +23,7 @@ jobs: steps: - run: exit 0 test-b: + continue-on-error: true runs-on: ubuntu-latest steps: - run: exit 1 From a8c2e1174373dd013f627dbdaf509f90c974d7b9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:30:17 +0200 Subject: [PATCH 08/23] ok --- .github/workflows/test-check-dependent-jobs.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 2396f54..398cd2d 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -23,10 +23,9 @@ jobs: steps: - run: exit 0 test-b: - continue-on-error: true runs-on: ubuntu-latest steps: - - run: exit 1 + - run: exit 0 test: if: always() runs-on: ubuntu-latest @@ -40,5 +39,4 @@ jobs: with: needs: ${{ toJSON(needs) }} - name: assert - run: | - test "${{ steps.check.outputs.is-success }}" = "false" + run: ${{ steps.check.outputs.is-success }} From db17170f8d575a4eb84eef09c295e529c4132f7e Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:37:40 +0200 Subject: [PATCH 09/23] fix paths --- .github/workflows/test-check-dependent-jobs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 398cd2d..b479620 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -6,13 +6,13 @@ on: - main paths: - '.github/workflows/test-check-dependent-jobs.yml' - - 'oblt-cli/test-check-dependent-jobs/**' + - 'oblt-cli/check-dependent-jobs/**' push: branches: - main paths: - '.github/workflows/test-check-dependent-jobs.yml' - - 'oblt-cli/test-check-dependent-jobs/**' + - 'oblt-cli/check-dependent-jobs/**' permissions: contents: read From 5cc8983b8e8b5a353c3eef2b767d875a347d2df5 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:37:59 +0200 Subject: [PATCH 10/23] fix paths --- .github/workflows/test-check-dependent-jobs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index b479620..3e2540d 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -6,13 +6,13 @@ on: - main paths: - '.github/workflows/test-check-dependent-jobs.yml' - - 'oblt-cli/check-dependent-jobs/**' + - 'check-dependent-jobs/**' push: branches: - main paths: - '.github/workflows/test-check-dependent-jobs.yml' - - 'oblt-cli/check-dependent-jobs/**' + - 'check-dependent-jobs/**' permissions: contents: read From 74b7301e115a1dc24d751d60339e3aa1ae7f2e52 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:44:10 +0200 Subject: [PATCH 11/23] modify test --- .../workflows/test-check-dependent-jobs.yml | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 3e2540d..a22b7b6 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -18,25 +18,19 @@ permissions: contents: read jobs: - test-a: - runs-on: ubuntu-latest - steps: - - run: exit 0 - test-b: - runs-on: ubuntu-latest - steps: - - run: exit 0 test: - if: always() runs-on: ubuntu-latest - needs: - - test-a - - test-b steps: - uses: actions/checkout@v4 - uses: ./check-dependent-jobs id: check with: - needs: ${{ toJSON(needs) }} + needs: '{ "job-a": { result: "success" }, "job-b": { result: "success" } }' + - name: assert + run: test "${{ steps.check.outputs.is-success }}" = "true" + - uses: ./check-dependent-jobs + id: check-2 + with: + needs: '{ "job-a": { result: "success" }, "job-b": { result: "failure" } }' - name: assert - run: ${{ steps.check.outputs.is-success }} + run: test "${{ steps.check-2.outputs.is-success }}" = "false" From bf157f8a488d0b9fa3ef7fce4f5450bea8fb7cde Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:44:56 +0200 Subject: [PATCH 12/23] fix --- .github/workflows/test-check-dependent-jobs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index a22b7b6..3668ce5 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -25,12 +25,12 @@ jobs: - uses: ./check-dependent-jobs id: check with: - needs: '{ "job-a": { result: "success" }, "job-b": { result: "success" } }' + needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "success" } }' - name: assert run: test "${{ steps.check.outputs.is-success }}" = "true" - uses: ./check-dependent-jobs id: check-2 with: - needs: '{ "job-a": { result: "success" }, "job-b": { result: "failure" } }' + needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "failure" } }' - name: assert run: test "${{ steps.check-2.outputs.is-success }}" = "false" From 97fcc6aec8f7db82db4abc95fad75b26fbd5b28e Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 30 May 2024 09:46:24 +0200 Subject: [PATCH 13/23] Add test case --- .github/workflows/test-check-dependent-jobs.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 3668ce5..6b1ccd4 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -34,3 +34,9 @@ jobs: needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "failure" } }' - name: assert run: test "${{ steps.check-2.outputs.is-success }}" = "false" + - uses: ./check-dependent-jobs + id: check-3 + with: + needs: '{ "job-a": { "result": "failure" }, "job-b": { "result": "failure" } }' + - name: assert + run: test "${{ steps.check-3.outputs.is-success }}" = "false" From 709a5942bf67c272cbf6852f2c3d6f64f5a02f43 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 31 May 2024 01:01:52 +0200 Subject: [PATCH 14/23] test --- check-dependent-jobs/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index 8e1d5fd..ef639d3 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -18,6 +18,7 @@ runs: - id: test run: | echo "##[debug] needs: ${{ inputs.needs }}" + echo "##[debug] needs: ${{ needs }}" RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') echo "is-success=${RESULT}" >> $GITHUB_OUTPUT From 0ac83208dde8e86ae2392bfdc60abca23fdbe2ae Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 31 May 2024 01:04:44 +0200 Subject: [PATCH 15/23] add debug step --- check-dependent-jobs/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index ef639d3..4123523 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -15,11 +15,11 @@ outputs: runs: using: composite steps: + - if: ${{ runner.debug }} + run: echo "${{ inputs.needs }}" + shell: bash - id: test run: | - echo "##[debug] needs: ${{ inputs.needs }}" - echo "##[debug] needs: ${{ needs }}" - RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') echo "is-success=${RESULT}" >> $GITHUB_OUTPUT if [[ $RESULT == true ]]; then From ea77e52d6957770cd6e804479722761df6695209 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 31 May 2024 01:05:37 +0200 Subject: [PATCH 16/23] add path to no-test --- .github/workflows/no-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/no-test.yml b/.github/workflows/no-test.yml index c08e2bc..2f13272 100644 --- a/.github/workflows/no-test.yml +++ b/.github/workflows/no-test.yml @@ -7,6 +7,7 @@ on: paths: - '**' - '!.github/workflows/test-*' + - '!check-dependent-jobs/**' - '!git/setup/**' - '!google/auth/**' - '!updatecli/run/**' From e7d139b42bdfe0e8f4e13842170add3d45a2df40 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 31 May 2024 01:07:22 +0200 Subject: [PATCH 17/23] remove debug step; not needed --- check-dependent-jobs/action.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index 4123523..385fdb8 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -15,9 +15,6 @@ outputs: runs: using: composite steps: - - if: ${{ runner.debug }} - run: echo "${{ inputs.needs }}" - shell: bash - id: test run: | RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') From 059a02bc851bbb029a31c59ab31184948683aabe Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 3 Jun 2024 14:08:47 +0200 Subject: [PATCH 18/23] Add expected result in name --- .github/workflows/test-check-dependent-jobs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 6b1ccd4..4e22793 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -26,17 +26,17 @@ jobs: id: check with: needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "success" } }' - - name: assert + - name: assert outputs.is-success==true run: test "${{ steps.check.outputs.is-success }}" = "true" - uses: ./check-dependent-jobs id: check-2 with: needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "failure" } }' - - name: assert + - name: assert outputs.is-success==false run: test "${{ steps.check-2.outputs.is-success }}" = "false" - uses: ./check-dependent-jobs id: check-3 with: needs: '{ "job-a": { "result": "failure" }, "job-b": { "result": "failure" } }' - - name: assert + - name: assert outputs.is-success==true run: test "${{ steps.check-3.outputs.is-success }}" = "false" From 4767b10e3650a6e606eb4bbe9bccd67258e76a4a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 3 Jun 2024 14:10:41 +0200 Subject: [PATCH 19/23] Update check-dependent-jobs/README.md Co-authored-by: Victor Martinez --- check-dependent-jobs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check-dependent-jobs/README.md b/check-dependent-jobs/README.md index 11d43af..acdd679 100644 --- a/check-dependent-jobs/README.md +++ b/check-dependent-jobs/README.md @@ -1,4 +1,4 @@ -## About +# check-dependent-jobs Evaluates the combined the status results of the provided needs context. This is useful for creating a single status check. From e14f866c4f08a0d77f9463377053cb7c8d79c2a3 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 3 Jun 2024 14:12:14 +0200 Subject: [PATCH 20/23] Rename 'needs' input to 'jobs' --- .github/workflows/test-check-dependent-jobs.yml | 6 +++--- check-dependent-jobs/README.md | 8 ++++---- check-dependent-jobs/action.yml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 4e22793..89c45f2 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -25,18 +25,18 @@ jobs: - uses: ./check-dependent-jobs id: check with: - needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "success" } }' + jobs: '{ "job-a": { "result": "success" }, "job-b": { "result": "success" } }' - name: assert outputs.is-success==true run: test "${{ steps.check.outputs.is-success }}" = "true" - uses: ./check-dependent-jobs id: check-2 with: - needs: '{ "job-a": { "result": "success" }, "job-b": { "result": "failure" } }' + jobs: '{ "job-a": { "result": "success" }, "job-b": { "result": "failure" } }' - name: assert outputs.is-success==false run: test "${{ steps.check-2.outputs.is-success }}" = "false" - uses: ./check-dependent-jobs id: check-3 with: - needs: '{ "job-a": { "result": "failure" }, "job-b": { "result": "failure" } }' + jobs: '{ "job-a": { "result": "failure" }, "job-b": { "result": "failure" } }' - name: assert outputs.is-success==true run: test "${{ steps.check-3.outputs.is-success }}" = "false" diff --git a/check-dependent-jobs/README.md b/check-dependent-jobs/README.md index acdd679..e68f3d7 100644 --- a/check-dependent-jobs/README.md +++ b/check-dependent-jobs/README.md @@ -10,9 +10,9 @@ in combination with the `notify-built-status` action. Following inputs can be used as `step.with` keys -| Name | Type | Default | Description | -|--------------|---------|-----------------------------|----------------------------------| -| `needs` | String | | JSON string of the needs context | +| Name | Type | Default | Description | +|--------|---------|-----------------------------|----------------------------------| +| `jobs` | String | | JSON string of the needs context | ## Outputs @@ -44,6 +44,6 @@ jobs: - id: check uses: elastic/oblt-actions/check-dependent-jobs@v1 with: - needs: ${{ toJSON(needs) }} + jobs: ${{ toJSON(needs) }} - run: ${{ steps.check.outputs.is-success }} # should exit with 1 or 0. ``` diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index 385fdb8..9943e1e 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -2,7 +2,7 @@ name: check-dependent-jobs description: | Evaluates the combined the status results of the provided needs context. inputs: - needs: + jobs: required: true description: needs context as JSON string outputs: @@ -17,7 +17,7 @@ runs: steps: - id: test run: | - RESULT=$(echo '${{ inputs.needs }}' | jq -s 'map(.[].result) | all(.=="success")') + RESULT=$(echo '${{ inputs.jobs }}' | jq -s 'map(.[].result) | all(.=="success")') echo "is-success=${RESULT}" >> $GITHUB_OUTPUT if [[ $RESULT == true ]]; then STATUS=success From 6d402476a15d07aff522ba1c369a3fabb7312894 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 3 Jun 2024 14:13:14 +0200 Subject: [PATCH 21/23] Fix name --- .github/workflows/test-check-dependent-jobs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-check-dependent-jobs.yml b/.github/workflows/test-check-dependent-jobs.yml index 89c45f2..35b6e2c 100644 --- a/.github/workflows/test-check-dependent-jobs.yml +++ b/.github/workflows/test-check-dependent-jobs.yml @@ -38,5 +38,5 @@ jobs: id: check-3 with: jobs: '{ "job-a": { "result": "failure" }, "job-b": { "result": "failure" } }' - - name: assert outputs.is-success==true + - name: assert outputs.is-success==false run: test "${{ steps.check-3.outputs.is-success }}" = "false" From 0e8037f0f1e1166e82fc37a50c7302dd104fe3ca Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 3 Jun 2024 14:19:13 +0200 Subject: [PATCH 22/23] Use github-script --- check-dependent-jobs/action.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/check-dependent-jobs/action.yml b/check-dependent-jobs/action.yml index 9943e1e..9725caf 100644 --- a/check-dependent-jobs/action.yml +++ b/check-dependent-jobs/action.yml @@ -16,13 +16,12 @@ runs: using: composite steps: - id: test - run: | - RESULT=$(echo '${{ inputs.jobs }}' | jq -s 'map(.[].result) | all(.=="success")') - echo "is-success=${RESULT}" >> $GITHUB_OUTPUT - if [[ $RESULT == true ]]; then - STATUS=success - else - STATUS=failure - fi - echo "status=${STATUS}" >> $GITHUB_OUTPUT - shell: bash + uses: actions/github-script@v7 + with: + script: | + const jobs = JSON.parse(process.env.JOBS) + const isSuccess = Object.values(jobs).every(job => job.result === 'success') + core.setOutput('is-success', isSuccess) + core.setOutput('status', isSuccess ? 'success' : 'failure') + env: + JOBS: ${{ inputs.jobs }} From 8b2b0ea949ba55d33b19108bb1d1da91f1eb4d9c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 11:35:35 +0200 Subject: [PATCH 23/23] Update README.md --- check-dependent-jobs/README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/check-dependent-jobs/README.md b/check-dependent-jobs/README.md index e68f3d7..8a1b480 100644 --- a/check-dependent-jobs/README.md +++ b/check-dependent-jobs/README.md @@ -1,29 +1,28 @@ -# check-dependent-jobs +# check-dependent-jobs + Evaluates the combined the status results of the provided needs context. -This is useful for creating a single status check. - -That status check can then be set as required status check, or it can be used -in combination with the `notify-built-status` action. + ## Inputs - -Following inputs can be used as `step.with` keys - -| Name | Type | Default | Description | -|--------|---------|-----------------------------|----------------------------------| -| `jobs` | String | | JSON string of the needs context | + +| Name | Description | Required | Default | +|--------|------------------------------|----------|---------| +| `jobs` | needs context as JSON string | `true` | ` ` | + ## Outputs -| Name | Type | Description | -|--------------|---------|------------------------------------| -| `is-success` | Boolean | If all jobs are successful or not. | -| `status` | String | `success` or `failure` | - + +| Name | Description | +|--------------|-----------------------------------------------------------------| +| `is-success` | The evaluated result of all provided jobs in the needs context. | +| `status` | One of success or failure. | + ## Usage + ```yaml jobs: job-a: @@ -47,3 +46,4 @@ jobs: jobs: ${{ toJSON(needs) }} - run: ${{ steps.check.outputs.is-success }} # should exit with 1 or 0. ``` +