Make action more modular

This commit is contained in:
Rodrigo Q. Saramago 2022-11-01 18:49:57 -03:00 committed by Nikola Matic
parent a7f8b63507
commit a257fddf24
2 changed files with 55 additions and 19 deletions

49
.github/actions/stale_issues/action.yml vendored Normal file
View File

@ -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

View File

@ -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')