Skip to content

Commit

Permalink
ci: update workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Polyakov <djeredian@gmail.com>
  • Loading branch information
Jeredian committed Mar 5, 2024
1 parent eec2f06 commit ad14245
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 6 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/documentation-update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "Documentation / Changelog"

on:
release:
types:
- released

jobs:
update:
name: Update Changelog
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# updated CHANGELOG back to the repository.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write

steps:
- name: Generate token
uses: tibdex/github-app-token@v2.1.0
id: generate_token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch entire history of repository to ensure release date can be
# extracted from commit of the given tag.
fetch-depth: 0
# Checkout target branch of this release. Ensures that the CHANGELOG
# is not out of date.
ref: ${{ github.event.release.target_commitish }}
token: ${{ steps.generate_token.outputs.token }}

- name: Extract release date from git tag
id: release_date
run: |
echo "date=$(git log -1 --date=short --format=%ad '${{ github.event.release.tag_name }}')" >> $GITHUB_OUTPUT;
- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1.10.0
with:
# Pass extracted release date, release notes and version to the Action.
release-date: ${{ steps.release_date.outputs.date }}
release-notes: ${{ github.event.release.body }}
latest-version: ${{ github.event.release.name }}
parse-github-usernames: true

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6.0.0
with:
token: ${{ steps.generate_token.outputs.token }}
branch: 'docs/update-changelog-${{ github.event.release.name }}'
branch-suffix: short-commit-hash
delete-branch: true
draft: false
committer: 'Print Maker Lab [bot] <831143+printmakerlab-bot[bot]@users.noreply.github.com>'
author: 'Print Maker Lab [bot]'
commit-message: 'docs(changelog): update changelog'
signoff: true
title: 'docs(changelog): update changelog'
body: |
Automated changelog PR for release: `${{ github.event.release.name }}`
labels: |
pull request: documentation
pull request: skip-changelog
26 changes: 26 additions & 0 deletions .github/workflows/housekeeping-stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Housekeeping / Stale"
on:
schedule:
- cron: '0 8 * * *'

jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9.0.0
with:
any-of-issue-labels:
"status: waiting response,status: needs more info"
only-pr-labels: ''
stale-issue-message: |
This issue has been marked as stale because it has required additional
info or a response from the author for over 7 days. When you get the
chance, please comment with the additional info requested.
Otherwise, this issue will be closed in 7 days.
close-issue-message: |
This issue has been closed because it has received no activity for
14 days.
stale-issue-label: 'status: stale'
days-before-stale: 7
days-before-close: 7
debug-only: true
66 changes: 66 additions & 0 deletions .github/workflows/issue-new-issues-triage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "Issue / New issue triage"
on:
issues:
types: [labeled, opened]

permissions:
issues: write

jobs:
add-comment-to-enhancement:
name: "On enhancement"
runs-on: ubuntu-latest
if: ${{ contains(github.event.label.name, format('issue{0} enhancement', ':')) && contains(github.event.label.name, format('status{0} pending', ':')) }}
steps:
- name: Log github event
env:
$GITHUB_CONTEXT_LABELS: ${{ toJson(github.event.label) }}
run: echo "$GITHUB_CONTEXT_LABELS"
- name: Add comment
uses: actions/github-script@v7.0.1
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
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.'
})
add-comment-to-bug:
name: "On bug report"
runs-on: ubuntu-latest
if: ${{ contains(github.event.label.name, format('issue{0} bug', ':')) && contains(github.event.label.name, format('status{0} pending', ':')) }}
steps:
- name: Log github event
env:
$GITHUB_CONTEXT_LABELS: ${{ toJson(github.event.label) }}
run: echo "$GITHUB_CONTEXT_LABELS"
- name: Add comment
uses: actions/github-script@v7.0.1
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
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.'
})
add-comment-to-question:
name: "On question"
runs-on: ubuntu-latest
if: ${{ contains(github.event.label.name, format('issue{0} question', ':')) && contains(github.event.label.name, format('status{0} pending', ':')) }}
steps:
- name: Log github event
env:
$GITHUB_CONTEXT_LABELS: ${{ toJson(github.event.label) }}
run: echo "$GITHUB_CONTEXT_LABELS"
- name: Add comment
uses: actions/github-script@v7.0.1
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thank you for submitting your question. Your question will be reviewed shortly by the Print Maker Lab team.'
})
35 changes: 35 additions & 0 deletions .github/workflows/project-automation-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Project Automation / Issue
on:
issues:
types: [opened, reopened, labeled]
workflow_call:
secrets:
ADD_TO_PROJECT_PAT:
required: true

env:
KANBAN_PROJECT_URL: https://github.com/orgs/PrintMakerLab/projects/3
TRACKER_PROJECT_URL: https://github.com/orgs/PrintMakerLab/projects/4
LABEL_BUG: 'issue: bug'
LABEL_SECURITY: 'issue: security'
LABEL_BACKLOG: 'status: backlog'

jobs:
add-to-kanban-project:
name: Add security, bug and team selected issues to the Kanban project
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v0.5.0
with:
labeled: ${{ env.LABEL_BUG }}, ${{ env.LABEL_BACKLOG }}, ${{ env.LABEL_SECURITY }}
project-url: ${{ env.KANBAN_PROJECT_URL }}
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}

add-to-tracker-project:
name: Add all issues to the Issue tracker project
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v0.5.0
with:
project-url: ${{ env.TRACKER_PROJECT_URL }}
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
21 changes: 21 additions & 0 deletions .github/workflows/project-automation-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Project Automation / Pull Request
on:
pull_request_target:
types: [opened, reopened]
workflow_call:
secrets:
ADD_TO_PROJECT_PAT:
required: true

env:
KANBAN_PROJECT_URL: https://github.com/orgs/PrintMakerLab/projects/3

jobs:
add-to-kanban-project:
name: Add all pull requests to the Kanban project
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v0.5.0
with:
project-url: ${{ env.KANBAN_PROJECT_URL }}
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
51 changes: 51 additions & 0 deletions .github/workflows/pull-request-labels-automation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Pull request / Labels "

on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

jobs:
label:
if: github.event.pull_request.labels[0] == null
name: "Assign labels"
runs-on: ubuntu-latest
steps:
- name: Generate token
uses: tibdex/github-app-token@v2.1.0
id: generate_token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: "Apply label"
uses: bcoe/conventional-release-labels@v1.3.1
with:
token: ${{ steps.generate_token.outputs.token }}
# Labels assigned based on pr name prefix
type_labels: >
{
"feat": "pull request: feature-minor",
"fix": "pull request: bug",
"build": "pull request: maintenance",
"ci": "pull request: maintenance",
"refactor": "pull request: maintenance",
"test": "pull request: maintenance",
"style": "pull request: maintenance",
"translation": "pull request: translation",
"docs": "pull request: documentation",
"revert": "pull request: skip-changelog"
}
# Do not ignore any labels (default ignores chore:)
ignored_types: '[]'
50 changes: 50 additions & 0 deletions .github/workflows/pull-request-on-closed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: "Pull resquest / On Close"
on:
pull_request_target:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Cleanup up branch cache
run: |
gh extension install actions/gh-actions-cache
echo "Fetching list of cache keys"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Comment the schedule release
id: conditional-comment
uses: actions/github-script@v7.0.1
with:
script: |
const commentText = "The content of this pull request will be made available as part of our next release."
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentText
});
- name: Set Output
if: steps.conditional-comment.outcome == 'success'
run: echo "Comment added successfully."
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
name: "Pull Request Labels Validation"
name: "Pull request / Validation / Labels"

on:
pull_request:
pull_request_target:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled


concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
check_pull_request_labels:
name: "Check pull request labels"
name: "Required labels"
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Sleep for 10 seconds
run: sleep 10s
shell: bash
- uses: mheap/github-action-required-labels@v5
with:
mode: "exactly"
mode: "minimum"
count: 1
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"
add_comment: true
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."
- uses: mheap/github-action-required-labels@v5
with:
mode: "maximum"
count: 1
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"
add_comment: true
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."
check_issue_labels:
name: "Check issue labels"
name: "Redudant labels"
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Sleep for 10 seconds
run: sleep 10s
shell: bash
- uses: mheap/github-action-required-labels@v5
with:
mode: "exactly"
Expand Down
Loading

0 comments on commit ad14245

Please sign in to comment.