From a257fddf24e3379305dee2515a2d642a22d927d5 Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Tue, 1 Nov 2022 18:49:57 -0300 Subject: [PATCH] Make action more modular --- .github/actions/stale_issues/action.yml | 49 +++++++++++++++++++++++++ .github/workflows/stale-issues.yml | 25 +++---------- 2 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 .github/actions/stale_issues/action.yml diff --git a/.github/actions/stale_issues/action.yml b/.github/actions/stale_issues/action.yml new file mode 100644 index 000000000..7cc82af2c --- /dev/null +++ b/.github/actions/stale_issues/action.yml @@ -0,0 +1,49 @@ +name: Filter stale issues +inputs: + token: + description: 'The GITHUB_TOKEN secret' + required: true + period: + description: "The stale period in days" + required: false + type: number + default: 14 + repo: + description: "The target repository" + required: false + type: string + default: "${{ github.repository_owner }}/${{ github.event.repository.name }}" +outputs: + result: + description: "The result of the query" + value: ${{ steps.found_issues.outputs.result }} + +runs: + using: "composite" + steps: + - name: Get period date + id: date + shell: bash + run: | + period_date=$(date --date "${{ inputs.period }} days ago" --utc +"%Y-%m-%dT%H:%M:%SZ") + echo "period=$period_date" >> $GITHUB_OUTPUT + - name: Get inactive open issues + id: stale_issues + if: ${{ success() }} + uses: ethereum/solidity/.github/actions/query_issues@develop + with: + token: ${{ inputs.token }} + query: 'repo:${{ inputs.repo }} is:issue is:open updated:<${{ steps.date.outputs.period }}' + - name: Collect query result + id: found_issues + if: ${{ success() }} + shell: bash + run: | + filter_result=$( + jq --raw-output \ + --null-input \ + --argjson result '${{ steps.stale_issues.outputs.query_result }}' \ + '[$result.data.search.nodes[].url] | @sh' \ + | tr --delete \' + ) + echo "result=$filter_result" >> $GITHUB_OUTPUT diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml index a1bb1a053..11e544ed6 100644 --- a/.github/workflows/stale-issues.yml +++ b/.github/workflows/stale-issues.yml @@ -1,12 +1,12 @@ name: Check stale issues on: + workflow_dispatch: # FIXME: remove schedule: - cron: '0 12 * * *' env: PERIOD: 14 # in days - REPO: "${{ github.repository_owner }}/${{ github.event.repository.name }}" WAIT_FOR_INFO: "waiting for more input" DRY_RUN: true @@ -15,33 +15,20 @@ jobs: name: Retrieve all open issues that are inactive runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.5.0 - - name: Get period date - id: date - run: | - period_date=$(date --date "$PERIOD days ago" --utc +"%Y-%m-%dT%H:%M:%SZ") - echo "period=$period_date" >> $GITHUB_OUTPUT + - uses: actions/checkout@v3 - name: Get inactive open issues - if: ${{ success() }} id: stale_issues - uses: ./.github/actions/query_issues + uses: ./.github/actions/stale_issues with: token: ${{ secrets.GITHUB_TOKEN }} - query: 'repo:${{ env.REPO }} is:issue is:open updated:<${{ steps.date.outputs.period }}' + period: ${{ env.PERIOD }} - name: Comment on found issues if: ${{ success() }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - query_result=$( - jq --raw-output \ - --null-input \ - --argjson result '${{ steps.stale_issues.outputs.query_result }}' \ - '[$result.data.search.nodes[].url] | @sh' \ - | tr --delete \' - ) - for issue_url in $query_result; do - # Filter issues that were triaged and are not waiting for more information + for issue_url in ${{ steps.stale_issues.outputs.result }}; do + # Filter stale issues that were triaged and are not waiting for more information stale_triaged=$(gh issue view $issue_url \ --json labels \ --jq '.labels | map(.name != "$WAIT_FOR_INFO") | all and length > 0')