From 7d05dce5e23edf26c62d3e1bc12f87f6993209e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Tue, 24 Dec 2024 12:04:37 +0300 Subject: [PATCH] ci(require-label): add new reusable workflow (#331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: M. Fatih Cırıt --- .github/workflows/require-label.yaml | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/require-label.yaml diff --git a/.github/workflows/require-label.yaml b/.github/workflows/require-label.yaml new file mode 100644 index 00000000..529ea7ef --- /dev/null +++ b/.github/workflows/require-label.yaml @@ -0,0 +1,37 @@ +name: require-label + +on: + workflow_call: + inputs: + label: + required: true + type: string + outputs: + result: + value: ${{ jobs.require-label.outputs.result }} + +jobs: + require-label: + runs-on: ubuntu-latest + outputs: + result: ${{ steps.require-label.outputs.result }} + steps: + - name: Check if label is present + id: check-for-label + if: contains(github.event.pull_request.labels.*.name, inputs.label) + run: | + echo "result=true" >> $GITHUB_OUTPUT + echo "::notice::✅ The label is present: '${{ inputs.label }}'" + shell: bash + + - name: Fail if label is not present + if: steps.check-for-label.outputs.result != 'true' + run: | + echo "::error::❌ The label is missing: '${{ inputs.label }}'" + echo "result=false" >> $GITHUB_OUTPUT + echo "## 🚨 Missing Required Label" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "💡 Please add the following label to the pull request to proceed:" >> $GITHUB_STEP_SUMMARY + echo "▶️ **${{ inputs.label }}**" >> $GITHUB_STEP_SUMMARY + exit 1 + shell: bash