From 694a320a00ea7d4242cd67b16fe2c9e0df8168ff Mon Sep 17 00:00:00 2001 From: "Jose R. Gonzalez" Date: Wed, 9 Aug 2023 10:53:12 -0500 Subject: [PATCH] Create action to disable specific workflows based on repo config Signed-off-by: Jose R. Gonzalez --- .github/workflows/ci-enabled.yml | 41 +++++++++++++++++++++++++++ .github/workflows/test-ci-enabled.yml | 14 +++++++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/ci-enabled.yml create mode 100644 .github/workflows/test-ci-enabled.yml diff --git a/.github/workflows/ci-enabled.yml b/.github/workflows/ci-enabled.yml new file mode 100644 index 00000000000..e4a36ef02ab --- /dev/null +++ b/.github/workflows/ci-enabled.yml @@ -0,0 +1,41 @@ +name: Ensure CI is Enabled +# This workflow allows a project to disable workflows based on a repository or +# organizational environment variable. +# +# Create a repo or org environment variable with its value set to 'true' +# for this workflow to succeed. Any other value should cause this workflow +# to fail. +# +# https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository +# +# Example usage, assuming this workflow is local to your repository: +# +# jobs: +# ensure_ci_enabled: +# uses: ./.github/workflows/check-ci-enabled.yml +# with: +# is-enabled: ${{ vars.CUSTOM_VAR_CI_ENABLED }} +# +# next_task: +# needs: ensure_ci_enabled +# runs-on: ubuntu-latest +# steps: +# - ... + +on: + workflow_call: + inputs: + is-enabled: + type: string + required: true + +jobs: + fail_if_ci_disabled: + runs-on: ubuntu-latest + steps: + - name: Check enablement value + run: | + test "${{ inputs.is-enabled }}" = "true" \ + || { echo "::error::Halting because this repo/org/env configuration has not explicitly enabled this CI."; \ + exit 1 ;} + echo "::notice::CI is enabled!" \ No newline at end of file diff --git a/.github/workflows/test-ci-enabled.yml b/.github/workflows/test-ci-enabled.yml new file mode 100644 index 00000000000..87f1c644b50 --- /dev/null +++ b/.github/workflows/test-ci-enabled.yml @@ -0,0 +1,14 @@ +name: Test CERTIFICATION_ENABLED + +# A developer convenience workflow. +# Tests to see if the CERTIFICATION_ENABLED value indicates +# certification is enabled. + +on: + workflow_dispatch: + +jobs: + test_certification_enabled: + uses: ./.github/workflows/ci-enabled.yml + with: + is-enabled: ${{ vars.CERTIFICATION_ENABLED }}