Skip to content

Commit e405e32

Browse files
authored
ci: update workflows (#411)
Signed-off-by: Pavel Polyakov <[email protected]>
1 parent eec2f06 commit e405e32

9 files changed

+416
-6
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: "Documentation / Changelog"
2+
3+
on:
4+
release:
5+
types:
6+
- released
7+
8+
jobs:
9+
update:
10+
name: Update Changelog
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
# Give the default GITHUB_TOKEN write permission to commit and push the
15+
# updated CHANGELOG back to the repository.
16+
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
17+
contents: write
18+
19+
steps:
20+
- name: Generate token
21+
uses: tibdex/[email protected]
22+
id: generate_token
23+
with:
24+
app_id: ${{ secrets.APP_ID }}
25+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
26+
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
# Fetch entire history of repository to ensure release date can be
31+
# extracted from commit of the given tag.
32+
fetch-depth: 0
33+
# Checkout target branch of this release. Ensures that the CHANGELOG
34+
# is not out of date.
35+
ref: ${{ github.event.release.target_commitish }}
36+
token: ${{ steps.generate_token.outputs.token }}
37+
38+
- name: Extract release date from git tag
39+
id: release_date
40+
run: |
41+
echo "date=$(git log -1 --date=short --format=%ad '${{ github.event.release.tag_name }}')" >> $GITHUB_OUTPUT;
42+
43+
- name: Update Changelog
44+
uses: stefanzweifel/[email protected]
45+
with:
46+
# Pass extracted release date, release notes and version to the Action.
47+
release-date: ${{ steps.release_date.outputs.date }}
48+
release-notes: ${{ github.event.release.body }}
49+
latest-version: ${{ github.event.release.name }}
50+
parse-github-usernames: true
51+
52+
- name: Create Pull Request
53+
uses: peter-evans/[email protected]
54+
with:
55+
token: ${{ steps.generate_token.outputs.token }}
56+
branch: 'docs/update-changelog-${{ github.event.release.name }}'
57+
branch-suffix: short-commit-hash
58+
delete-branch: true
59+
draft: false
60+
committer: 'Print Maker Lab [bot] <831143+printmakerlab-bot[bot]@users.noreply.github.com>'
61+
author: 'Print Maker Lab [bot]'
62+
commit-message: 'docs(changelog): update changelog'
63+
signoff: true
64+
title: 'docs(changelog): update changelog'
65+
body: |
66+
Automated changelog PR for release: `${{ github.event.release.name }}`
67+
labels: |
68+
pull request: documentation
69+
pull request: skip-changelog
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Housekeeping / Stale"
2+
on:
3+
schedule:
4+
- cron: '0 8 * * *'
5+
6+
jobs:
7+
comment:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/[email protected]
11+
with:
12+
any-of-issue-labels:
13+
"status: waiting response,status: needs more info"
14+
only-pr-labels: ''
15+
stale-issue-message: |
16+
This issue has been marked as stale because it has required additional
17+
info or a response from the author for over 7 days. When you get the
18+
chance, please comment with the additional info requested.
19+
Otherwise, this issue will be closed in 7 days.
20+
close-issue-message: |
21+
This issue has been closed because it has received no activity for
22+
14 days.
23+
stale-issue-label: 'status: stale'
24+
days-before-stale: 7
25+
days-before-close: 7
26+
debug-only: true
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: "Issue / New issue triage"
2+
on:
3+
issues:
4+
types: [labeled, opened]
5+
6+
permissions:
7+
issues: write
8+
9+
jobs:
10+
add-comment-to-enhancement:
11+
name: "On enhancement"
12+
runs-on: ubuntu-latest
13+
if: ${{ contains(github.event.label.name, format('issue{0} enhancement', ':')) && contains(github.event.label.name, format('status{0} pending', ':')) }}
14+
steps:
15+
- name: Log github event
16+
env:
17+
$GITHUB_CONTEXT_LABELS: ${{ toJson(github.event.label) }}
18+
run: echo "$GITHUB_CONTEXT_LABELS"
19+
- name: Add comment
20+
uses: actions/[email protected]
21+
with:
22+
script: |
23+
github.rest.issues.createComment({
24+
issue_number: context.issue.number,
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
body: 'Thank you for submitting a feature request. Your proposal is open and will soon be reviewed by the Print Maker Lab team.<br><br>If your proposal is accepted and the Print Maker Lab team has bandwidth they will take on the issue, or else request you or other volunteers from the community to work on this issue.'
28+
})
29+
add-comment-to-bug:
30+
name: "On bug report"
31+
runs-on: ubuntu-latest
32+
if: ${{ contains(github.event.label.name, format('issue{0} bug', ':')) && contains(github.event.label.name, format('status{0} pending', ':')) }}
33+
steps:
34+
- name: Log github event
35+
env:
36+
$GITHUB_CONTEXT_LABELS: ${{ toJson(github.event.label) }}
37+
run: echo "$GITHUB_CONTEXT_LABELS"
38+
- name: Add comment
39+
uses: actions/[email protected]
40+
with:
41+
script: |
42+
github.rest.issues.createComment({
43+
issue_number: context.issue.number,
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
body: 'Thank you for submitting a bug report. Your message will be reviewed shortly by the Print Maker Lab team.<br><br>If your request is reproducible and the Print Maker Lab team has the bandwidth, they will look into it, or ask you or other community volunteers to work on it.'
47+
})
48+
add-comment-to-question:
49+
name: "On question"
50+
runs-on: ubuntu-latest
51+
if: ${{ contains(github.event.label.name, format('issue{0} question', ':')) && contains(github.event.label.name, format('status{0} pending', ':')) }}
52+
steps:
53+
- name: Log github event
54+
env:
55+
$GITHUB_CONTEXT_LABELS: ${{ toJson(github.event.label) }}
56+
run: echo "$GITHUB_CONTEXT_LABELS"
57+
- name: Add comment
58+
uses: actions/[email protected]
59+
with:
60+
script: |
61+
github.rest.issues.createComment({
62+
issue_number: context.issue.number,
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
body: 'Thank you for submitting your question. Your question will be reviewed shortly by the Print Maker Lab team.'
66+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Project Automation / Issue
2+
on:
3+
issues:
4+
types: [opened, reopened, labeled]
5+
workflow_call:
6+
secrets:
7+
ADD_TO_PROJECT_PAT:
8+
required: true
9+
10+
env:
11+
KANBAN_PROJECT_URL: https://github.com/orgs/PrintMakerLab/projects/3
12+
TRACKER_PROJECT_URL: https://github.com/orgs/PrintMakerLab/projects/4
13+
LABEL_BUG: 'issue: bug'
14+
LABEL_SECURITY: 'issue: security'
15+
LABEL_BACKLOG: 'status: backlog'
16+
17+
jobs:
18+
add-to-kanban-project:
19+
name: Add security, bug and team selected issues to the Kanban project
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/[email protected]
23+
with:
24+
labeled: ${{ env.LABEL_BUG }}, ${{ env.LABEL_BACKLOG }}, ${{ env.LABEL_SECURITY }}
25+
project-url: ${{ env.KANBAN_PROJECT_URL }}
26+
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
27+
28+
add-to-tracker-project:
29+
name: Add all issues to the Issue tracker project
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/[email protected]
33+
with:
34+
project-url: ${{ env.TRACKER_PROJECT_URL }}
35+
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Project Automation / Pull Request
2+
on:
3+
pull_request_target:
4+
types: [opened, reopened]
5+
workflow_call:
6+
secrets:
7+
ADD_TO_PROJECT_PAT:
8+
required: true
9+
10+
env:
11+
KANBAN_PROJECT_URL: https://github.com/orgs/PrintMakerLab/projects/3
12+
13+
jobs:
14+
add-to-kanban-project:
15+
name: Add all pull requests to the Kanban project
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/[email protected]
19+
with:
20+
project-url: ${{ env.KANBAN_PROJECT_URL }}
21+
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Pull request / Labels "
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- reopened
8+
- edited
9+
- synchronize
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
contents: read
17+
pull-requests: write
18+
19+
jobs:
20+
label:
21+
if: github.event.pull_request.labels[0] == null
22+
name: "Assign labels"
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Generate token
26+
uses: tibdex/[email protected]
27+
id: generate_token
28+
with:
29+
app_id: ${{ secrets.APP_ID }}
30+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
31+
32+
- name: "Apply label"
33+
uses: bcoe/[email protected]
34+
with:
35+
token: ${{ steps.generate_token.outputs.token }}
36+
# Labels assigned based on pr name prefix
37+
type_labels: >
38+
{
39+
"feat": "pull request: feature-minor",
40+
"fix": "pull request: bug",
41+
"build": "pull request: maintenance",
42+
"ci": "pull request: maintenance",
43+
"refactor": "pull request: maintenance",
44+
"test": "pull request: maintenance",
45+
"style": "pull request: maintenance",
46+
"translation": "pull request: translation",
47+
"docs": "pull request: documentation",
48+
"revert": "pull request: skip-changelog"
49+
}
50+
# Do not ignore any labels (default ignores chore:)
51+
ignored_types: '[]'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
2+
name: "Pull resquest / On Close"
3+
on:
4+
pull_request_target:
5+
types:
6+
- closed
7+
8+
jobs:
9+
cleanup:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Cleanup up branch cache
13+
run: |
14+
gh extension install actions/gh-actions-cache
15+
16+
echo "Fetching list of cache keys"
17+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
18+
19+
## Setting this to not fail the workflow while deleting cache keys.
20+
set +e
21+
echo "Deleting caches..."
22+
for cacheKey in $cacheKeysForPR
23+
do
24+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
25+
done
26+
echo "Done"
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
REPO: ${{ github.repository }}
30+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
31+
if_merged:
32+
if: github.event.pull_request.merged == true
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Comment the schedule release
36+
id: conditional-comment
37+
uses: actions/[email protected]
38+
with:
39+
script: |
40+
const commentText = "The content of this pull request will be made available as part of our next release."
41+
42+
github.rest.issues.createComment({
43+
issue_number: context.issue.number,
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
body: commentText
47+
});
48+
- name: Set Output
49+
if: steps.conditional-comment.outcome == 'success'
50+
run: echo "Comment added successfully."

.github/workflows/validate_pull_request_labels.yml renamed to .github/workflows/pull-request-validation-labels.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,53 @@
1-
name: "Pull Request Labels Validation"
1+
name: "Pull request / Validation / Labels"
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types:
66
- opened
77
- synchronize
88
- reopened
99
- labeled
1010
- unlabeled
11-
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
14+
cancel-in-progress: true
15+
1216
jobs:
1317
check_pull_request_labels:
14-
name: "Check pull request labels"
18+
name: "Required labels"
1519
runs-on: ubuntu-latest
1620
permissions:
1721
issues: write
1822
pull-requests: write
1923
steps:
24+
- name: Sleep for 10 seconds
25+
run: sleep 10s
26+
shell: bash
2027
- uses: mheap/github-action-required-labels@v5
2128
with:
22-
mode: "exactly"
29+
mode: "minimum"
2330
count: 1
2431
labels: "pull request: breaking,pull request: bug,pull request: community,pull request: dependencies,pull request: documentation,pull request: feature-major,pull request: feature-minor,pull request: maintenance,pull request: skip-changelog,pull request: translation,dependencies"
2532
add_comment: true
2633
message: "This PR is being prevented from merging because you haven't added one of the `pull request:` labels. You'll need to add one of them before this PR can be merged."
34+
- uses: mheap/github-action-required-labels@v5
35+
with:
36+
mode: "maximum"
37+
count: 1
38+
labels: "pull request: breaking,pull request: bug,pull request: dependencies,pull request: documentation,pull request: feature-major,pull request: feature-minor,pull request: maintenance,pull request: translation"
39+
add_comment: true
40+
message: "This PR is being prevented from merging because you have added more than one `pull request:` label. You'll need to keep only one of them before this PR can be merged."
2741
check_issue_labels:
28-
name: "Check issue labels"
42+
name: "Redudant labels"
2943
runs-on: ubuntu-latest
3044
permissions:
3145
issues: write
3246
pull-requests: write
3347
steps:
48+
- name: Sleep for 10 seconds
49+
run: sleep 10s
50+
shell: bash
3451
- uses: mheap/github-action-required-labels@v5
3552
with:
3653
mode: "exactly"

0 commit comments

Comments
 (0)