Skip to content

Commit 26ea5aa

Browse files
committed
chore: refactor workflow to have only one job but one step for issues and other for PRs
New features: - run on push over this workflow - run manually have debug option to make a dry-run execution - run scheduled is every 6 hours at o'clock - Summary report is in table format instead of list items
1 parent 0cc90eb commit 26ea5aa

File tree

1 file changed

+132
-96
lines changed

1 file changed

+132
-96
lines changed

Diff for: .github/workflows/stale.yml

+132-96
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,201 @@
1-
name: Stale and close inactive issues/PRs
1+
name: Stale handler
22

33
on:
4-
schedule:
5-
- cron: "0 0,6,12,18 * * *" # every 6 hours at o'clock
6-
workflow_dispatch: # or manually
4+
push: # when push this files to branches....
5+
branches:
6+
- 'main'
7+
- 'gh-actions/test'
8+
paths:
9+
- '.github/workflows/stale.yml' # - this workflow
10+
workflow_dispatch: # manually
11+
inputs:
12+
debug-only:
13+
type: boolean
14+
description: 'If enabled, debug mode is on and then API calls that can alter your issues will not happen'
15+
required: true
16+
default: true
17+
schedule: # or
18+
- cron: "0 0,6,12,18 * * *" # every 6 hours at o'clock
719

820
permissions:
21+
# no checkout/branching needed
922
contents: none
10-
issues: read
11-
pull-requests: read
1223

13-
# This allows a subsequently queued workflow run to interrupt previous runs
24+
# This allows a subsequently queued workflow run to interrupt/wait for previous runs
1425
concurrency:
15-
group: '${{ github.workflow }} @ ${{ github.run_id }}'
16-
cancel-in-progress: true
26+
group: '${{ github.workflow }}'
27+
cancel-in-progress: false # true: interrupt, false = wait for
1728

1829
jobs:
19-
20-
process-issues:
21-
name: Process Issues
22-
# This allows a subsequently queued workflow run to wait for previous runs completion
23-
concurrency:
24-
group: '${{ github.workflow }} @ ${{ github.run_id }} :: issues'
25-
cancel-in-progress: false
26-
# export variables used by reporter job
30+
stale:
31+
name: Staler job
32+
runs-on: ubuntu-latest
2733
outputs:
28-
staled-issues: ${{ steps.stale.outputs.staled-issues-prs }}
29-
closed-issues: ${{ steps.stale.outputs.closed-issues-prs }}
30-
# enable write access rights to allow comment and labeling by bot
34+
# "XXX-len": the length of the "XXX" output object
35+
staled-issues: ${{ steps.set-staled.outputs.issues }}
36+
staled-issues-len: ${{ steps.set-staled.outputs.issues-len }}
37+
staled-prs: ${{ steps.set-staled.outputs.prs }}
38+
staled-prs-len: ${{ steps.set-staled.outputs.prs-len }}
39+
closed-issues: ${{ steps.set-closed.outputs.issues }}
40+
closed-issues-len: ${{ steps.set-closed.outputs.issues-len }}
41+
closed-prs: ${{ steps.set-closed.outputs.prs }}
42+
closed-prs-len: ${{ steps.set-closed.outputs.prs-len }}
43+
# enable write access rights to allow bot comments and labeling
3144
permissions:
3245
issues: write
33-
runs-on: ubuntu-latest
46+
pull-requests: write
3447
steps:
35-
- uses: actions/stale@v5
36-
id: staler
48+
- name: Stale issues
49+
uses: actions/stale@v5
50+
id: stale-issues
3751
with:
52+
debug-only: ${{ github.event.inputs.debug-only == 'true' }}
3853
operations-per-run: 30
39-
days-before-issue-stale: 60
40-
days-before-issue-close: 30
54+
days-before-stale: 60
55+
days-before-close: 30
56+
ignore-updates: false
57+
remove-stale-when-updated: true
4158
stale-issue-label: "stale"
4259
close-issue-label: "stale: closed"
4360
stale-issue-message: |
44-
This issue has been automatically marked as stale because it has not had activity during the last 60 days.
61+
This issue has been automatically marked as stale because it has not had recent activity during last 60 days :sleeping:
4562
46-
It will be closed if no further activity occurs on the next 30 days.
63+
It will be closed in 30 days if no further activity occurs. To unstale this issue, remove stale label or add a comment with a detailed explanation.
4764
48-
Thank you for your contributions.
65+
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest.
66+
67+
Thank you for your patience :heart:
4968
close-issue-message: |
5069
This issue has been automatically closed because it has been inactive during the last 30 days since being marked as stale.
5170
52-
Anyway, thank you for your contributions.
53-
remove-issue-stale-when-updated: true
71+
As author or maintainer, it can always be reopened if you see that carry on been useful.
72+
73+
Anyway, thank you for your interest in contribute :heart:
74+
close-issue-reason: not_planned
5475
exempt-issue-labels: "blocked,must,should,keep,:busts_in_silhouette: discussion,:eyes: Needs Review,:pushpin: pinned"
76+
# disable PR processing at all (this step is for treat issues)
5577
days-before-pr-stale: -1
5678
days-before-pr-close: -1
79+
ignore-pr-updates: true
80+
remove-pr-stale-when-updated: false
81+
stale-pr-label: " "
5782

58-
- name: Set outputs
59-
## Removing private properties from each JSON object.
60-
## TODO: Remove this ugly fix for actions/stale#806
61-
id: stale
62-
run: |
63-
echo $STALED \
64-
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
65-
| sed -e 's/^/::set-output name=staled-issues-prs::/'
66-
echo $CLOSED \
67-
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
68-
| sed -e 's/^/::set-output name=closed-issues-prs::/'
69-
env:
70-
STALED: ${{ steps.staler.outputs.staled-issues-prs }}
71-
CLOSED: ${{ steps.staler.outputs.closed-issues-prs }}
83+
- name: Print outputs for issues
84+
run: echo ${{ join(steps.stale-issues.outputs.*, ',') }}
7285

73-
74-
process-prs:
75-
name: Process Pull Requests
76-
# This allows a subsequently queued workflow run to wait for previous runs completion
77-
concurrency:
78-
group: '${{ github.workflow }} @ ${{ github.run_id }} :: PRs'
79-
cancel-in-progress: false
80-
# export variables used by reporter job
81-
outputs:
82-
staled-prs: ${{ steps.stale.outputs.staled-issues-prs }}
83-
closed-prs: ${{ steps.stale.outputs.closed-issues-prs }}
84-
# enable write access rights to allow comment and labeling by bot
85-
permissions:
86-
pull-requests: write
87-
runs-on: ubuntu-latest
88-
steps:
89-
- uses: actions/stale@v5
90-
id: staler
86+
- name: Stale Pull Requests
87+
uses: actions/stale@v5
88+
id: stale-prs
9189
with:
90+
debug-only: ${{ github.event.inputs.debug-only == 'true' }}
9291
operations-per-run: 30
93-
days-before-pr-stale: 60
94-
days-before-pr-close: 30
92+
days-before-stale: 60
93+
days-before-close: 30
94+
ignore-updates: false
95+
remove-stale-when-updated: true
9596
stale-pr-label: "stale"
9697
close-pr-label: "stale: closed"
9798
stale-pr-message: |
98-
This pull request has been automatically marked as stale because it has not had activity during the last 60 days.
99+
This Pull Request has been automatically marked as stale because it has not had recent activity during last 60 days :sleeping:
100+
101+
It will be closed in 30 days if no further activity occurs. To unstale this PR, draft it, remove stale label, comment with a detailed explanation or push more commits.
99102
100-
It will be closed if no further activity occurs on the next 30 days.
103+
There can be many reasons why some specific PR has no activity. The most probable cause is lack of time, not lack of interest.
101104
102-
Thank you for your contributions.
105+
Thank you for your patience :heart:
103106
close-pr-message: |
104-
This pull request has been automatically closed because it has been inactive during the last 30 days since being marked as stale.
107+
This Pull Request has been automatically closed because it has been inactive during the last 30 days since being marked as stale.
105108
106-
Anyway, thank you for your contributions.
107-
remove-pr-stale-when-updated: true
108-
exempt-pr-labels: "blocked,must,should,keep,:busts_in_silhouette: discussion,:eyes: Needs Review"
109+
As author or maintainer, it can always be reopened if you see that carry on been useful.
110+
111+
Anyway, thank you for your interest in contribute :heart:
109112
exempt-draft-pr: true
113+
exempt-pr-labels: "blocked,must,should,keep,:busts_in_silhouette: discussion,:eyes: Needs Review"
114+
delete-branch: false # if true, job needs permissions "contents: write"
115+
# disable issues processing at all (this step is for treat PRs)
110116
days-before-issue-stale: -1
111117
days-before-issue-close: -1
118+
ignore-issue-updates: true
119+
remove-issue-stale-when-updated: false
120+
stale-issue-label: " "
121+
122+
- name: Print outputs for PRs
123+
run: echo ${{ join(steps.stale-prs.outputs.*, ',') }}
112124

113-
- name: Set outputs
114-
## Removing private properties from each JSON object.
115-
## TODO: Remove this ugly fix for actions/stale#806
116-
id: stale
125+
## Removing private properties from each JSON object and compute array length
126+
## TODO: Delete these set-* workarounds when resolve actions/stale#806 ?
127+
- name: Set staled
128+
id: set-staled
117129
run: |
118-
echo $STALED \
130+
echo $INPUT_ISSUES \
119131
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
120-
| sed -e 's/^/::set-output name=staled-issues-prs::/'
121-
echo $CLOSED \
132+
| sed -e 's/^/::set-output name=issues::/'
133+
echo $INPUT_ISSUES \
134+
| jq --raw-output '. | length' \
135+
| sed -e 's/^/::set-output name=issues-len::/'
136+
137+
echo $INPUT_PRS \
122138
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
123-
| sed -e 's/^/::set-output name=closed-issues-prs::/'
139+
| sed -e 's/^/::set-output name=prs::/'
140+
echo $INPUT_PRS \
141+
| jq --raw-output '. | length' \
142+
| sed -e 's/^/::set-output name=prs-len::/'
124143
env:
125-
STALED: ${{ steps.staler.outputs.staled-issues-prs }}
126-
CLOSED: ${{ steps.staler.outputs.closed-issues-prs }}
144+
INPUT_ISSUES: ${{ steps.stale-issues.outputs.staled-issues-prs }}
145+
INPUT_PRS: ${{ steps.stale-prs.outputs.staled-issues-prs }}
146+
- name: Set closed
147+
id: set-closed
148+
run: |
149+
echo $INPUT_ISSUES \
150+
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
151+
| sed -e 's/^/::set-output name=issues::/'
152+
echo $INPUT_ISSUES \
153+
| jq --raw-output '. | length' \
154+
| sed -e 's/^/::set-output name=issues-len::/'
127155
156+
echo $INPUT_PRS \
157+
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
158+
| sed -e 's/^/::set-output name=prs::/'
159+
echo $INPUT_PRS \
160+
| jq --raw-output '. | length' \
161+
| sed -e 's/^/::set-output name=prs-len::/'
162+
env:
163+
INPUT_ISSUES: ${{ steps.stale-issues.outputs.closed-issues-prs }}
164+
INPUT_PRS: ${{ steps.stale-prs.outputs.closed-issues-prs }}
128165

129-
reporter:
130-
name: GitHub reporter
131-
needs: [process-issues, process-prs]
132-
runs-on: ubuntu-latest
133-
steps:
134-
- run: |
166+
- name: Write job summary
167+
run: |
135168
echo "### Staled issues" \
136169
>> $GITHUB_STEP_SUMMARY
170+
# render json array to a Markdown table with an optional "No records" message if empty
137171
echo "$STALED_ISSUES" \
138-
| jq --raw-output 'map("* [#\(.number)](\(env.GITHUB_ISSUES_URL)/\(.number)): \(.title)") | join("\n")' \
172+
| jq --raw-output 'map("| [#\(.number)](\(env.GITHUB_ISSUES_URL)/\(.number)) | \(.title) |") | join("\n") | if (. == "") then "\nNo records.\n" else "\n| | Title |\n|---:|:------|\n\(.)\n" end' \
139173
>> $GITHUB_STEP_SUMMARY
140174
141175
echo "### Staled pull requests" \
142176
>> $GITHUB_STEP_SUMMARY
177+
# render json array to a Markdown table with an optional "No records" message if empty
143178
echo "$STALED_PRS" \
144-
| jq --raw-output 'map("* [#\(.number)](\(env.GITHUB_PULL_URL)/\(.number)): \(.title)") | join("\n")' \
179+
| jq --raw-output 'map("| [#\(.number)](\(env.GITHUB_PULL_URL)/\(.number)) | \(.title) |") | join("\n") | if (. == "") then "\nNo records.\n" else "\n| | Title |\n|---:|:------|\n\(.)\n" end' \
145180
>> $GITHUB_STEP_SUMMARY
146181
147182
echo "### Closed issues" \
148183
>> $GITHUB_STEP_SUMMARY
184+
# render json array to a Markdown table with an optional "No records" message if empty
149185
echo "$CLOSED_ISSUES" \
150-
| jq --raw-output 'map("* [#\(.number)](\(env.GITHUB_ISSUES_URL)/\(.number)): \(.title)") | join("\n")' \
186+
| jq --raw-output 'map("| [#\(.number)](\(env.GITHUB_ISSUES_URL)/\(.number)) | \(.title) |") | join("\n") | if (. == "") then "\nNo records.\n" else "\n| | Title |\n|---:|:------|\n\(.)\n" end' \
151187
>> $GITHUB_STEP_SUMMARY
152188
153189
echo "### Closed pull requests" \
154190
>> $GITHUB_STEP_SUMMARY
191+
# render json array to a Markdown table with an optional "No records" message if empty
155192
echo "$CLOSED_PRS" \
156-
| jq --raw-output 'map("* [#\(.number)](\(env.GITHUB_PULL_URL)/\(.number)): \(.title)") | join("\n")' \
193+
| jq --raw-output 'map("| [#\(.number)](\(env.GITHUB_PULL_URL)/\(.number)) | \(.title) |") | join("\n") | if (. == "") then "\nNo records.\n" else "\n| | Title |\n|---:|:------|\n\(.)\n" end' \
157194
>> $GITHUB_STEP_SUMMARY
158195
env:
159-
GITHUB_REPO_URL: ${{ format('{0}/{1}', github.server_url, github.repository) }}
160196
GITHUB_ISSUES_URL: ${{ format('{0}/{1}/issues', github.server_url, github.repository) }}
161197
GITHUB_PULL_URL: ${{ format('{0}/{1}/pull', github.server_url, github.repository) }}
162-
STALED_ISSUES: ${{ needs.process-issues.outputs.staled-issues }}
163-
CLOSED_ISSUES: ${{ needs.process-issues.outputs.closed-issues }}
164-
STALED_PRS: ${{ needs.process-prs.outputs.staled-prs }}
165-
CLOSED_PRS: ${{ needs.process-prs.outputs.closed-prs }}
198+
STALED_ISSUES: ${{ steps.set-staled.outputs.issues }}
199+
CLOSED_ISSUES: ${{ steps.set-closed.outputs.issues }}
200+
STALED_PRS: ${{ steps.set-staled.outputs.prs }}
201+
CLOSED_PRS: ${{ steps.set-closed.outputs.prs }}

0 commit comments

Comments
 (0)