From 4b709fa11942428ababeb4ebca2ab598aa1157cb Mon Sep 17 00:00:00 2001 From: Jamy Golden Date: Wed, 21 Aug 2024 20:48:54 +0200 Subject: [PATCH] Add workflow_call support to action and add action for repo reuse --- .github/CODEOWNERS | 1 + .github/workflows/auto-assign-issues.yml | 38 ++----------- .../workflows/shared-auto-assign-issues.yml | 54 +++++++++++++++++++ 3 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/shared-auto-assign-issues.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..485adf0 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @tinted-theming/admins diff --git a/.github/workflows/auto-assign-issues.yml b/.github/workflows/auto-assign-issues.yml index 047e22f..b3fef36 100644 --- a/.github/workflows/auto-assign-issues.yml +++ b/.github/workflows/auto-assign-issues.yml @@ -6,38 +6,6 @@ on: jobs: auto-assign: - runs-on: "ubuntu-latest" - permissions: - issues: "write" - outputs: - codeowners: ${{ steps.codeowners.outputs.value }} - steps: - - uses: actions/checkout@v4 - - name: "Get teams from CODEOWNERS file" - id: "codeowners" - run: | - result="" - first_item=true - - while IFS= read -r line; do - if [ "$first_item" = true ]; then - result="${line#* @tinted-theming/}" - first_item=false - else - result="$result, ${line#* @tinted-theming/}" - fi - done < .github/CODEOWNERS - - if [ -z "$result" ]; then - echo "Error: unable to determine teams from .github/CODEOWNERS file" - exit 1 - fi - - echo "value=$result" >> $GITHUB_OUTPUT - - - name: "Auto-assign issue" - uses: "pozil/auto-assign-issue@v2" - with: - repo-token: "${{ secrets.BOT_ACCESS_TOKEN }}" - teams: "${{ steps.codeowners.outputs.value }}" - numOfAssignee: 3 + uses: ./.github/workflows/shared-auto-assign-issues.yml + secrets: + token: ${{ secrets.BOT_ACCESS_TOKEN }} diff --git a/.github/workflows/shared-auto-assign-issues.yml b/.github/workflows/shared-auto-assign-issues.yml new file mode 100644 index 0000000..6fc0146 --- /dev/null +++ b/.github/workflows/shared-auto-assign-issues.yml @@ -0,0 +1,54 @@ +name: "Auto assignment for issues" + +on: + workflow_call: + secrets: + token: + description: "GitHub Access Token" + required: true + +jobs: + auto-assign: + runs-on: "ubuntu-latest" + permissions: + issues: "write" + outputs: + codeowners: ${{ steps.codeowners.outputs.value }} + steps: + - name: "Check token value" + run: | + token="${{ secrets.token }}" + if [ -z "$token" ]; then + echo "'secrets.token' not provided." + exit 1 + fi + + - uses: actions/checkout@v4 + - name: "Get teams from CODEOWNERS file" + id: "codeowners" + run: | + result="" + first_item=true + + while IFS= read -r line; do + if [ "$first_item" = true ]; then + result="${line#* @tinted-theming/}" + first_item=false + else + result="$result, ${line#* @tinted-theming/}" + fi + done < .github/CODEOWNERS + + if [ -z "$result" ]; then + echo "Error: unable to determine teams from .github/CODEOWNERS file" + exit 1 + fi + + echo "value=$result" >> $GITHUB_OUTPUT + + - name: "Auto-assign issue" + uses: "pozil/auto-assign-issue@v2" + with: + repo-token: "${{ secrets.token }}" + teams: "${{ steps.codeowners.outputs.value }}" + numOfAssignee: 3