From 4e0dbb304728793da1b1b543ef5413480d7af986 Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 13:47:54 +0800 Subject: [PATCH 01/10] chore: add github automations --- .github/release-drafter.yml | 26 +++++------ .github/workflows/auto-assign-author.yml | 14 ++++++ .../auto-label-conventional-commits.yaml | 44 +++++++++++++++++++ 3 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/auto-assign-author.yml create mode 100644 .github/workflows/auto-label-conventional-commits.yaml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 8e050404e..be409e020 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,20 +1,18 @@ categories: - - title: '🚀 Features' + - title: "🚀 Features" labels: - - 'type: enhancement' - - 'type: epic' - - 'type: feature request' - - title: '🐛 Bug Fixes' + - "type: feature request" + - "type: enhancement" + - "type: epic" + - title: "🐛 Fixes" labels: - - 'type: bug' - - title: '🧰 Maintenance' - labels: - - 'type: chore' - - 'type: ci' - - title: '📖 Documentaion' - labels: - - 'type: documentation' -change-template: '- $TITLE @$AUTHOR (#$NUMBER)' + - "type: bug" + - title: "🧰 Maintenance" + labels: + - "type: chore" + - "type: ci" + - "type: documentation" +change-template: "- $TITLE @$AUTHOR (#$NUMBER)" change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. template: | ## Changes diff --git a/.github/workflows/auto-assign-author.yml b/.github/workflows/auto-assign-author.yml new file mode 100644 index 000000000..1a120e67f --- /dev/null +++ b/.github/workflows/auto-assign-author.yml @@ -0,0 +1,14 @@ +# Auto assign author, tags, and reviewers to pull requests +name: "Auto Author Assign" +on: + pull_request: + types: [opened] +permissions: + pull-requests: write +jobs: + assign-author: + runs-on: ubuntu-latest + steps: + - uses: toshimaru/auto-author-assign@v1.1.0 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml new file mode 100644 index 000000000..13745d25b --- /dev/null +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -0,0 +1,44 @@ +name: "Auto Label Conventional Commits" +on: + issues: + types: [opened] + pull_request: + types: [opened] + +permissions: + issues: write + pull-requests: write + +jobs: + label_issues: + runs-on: ubuntu-latest + steps: + - name: Label issue + uses: actions/github-script@v5 + with: + script: | + const title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title; + const labelMapping = { + 'feat:': 'type: feature request', + 'perf:': 'type: enhancement', + 'fix:': 'type: bug', + 'docs:': 'type: documentation', + 'ci:': 'type: ci', + 'build:': 'type: ci', + 'chore:': 'type: chore', + 'test:': 'type: chore', + 'style:': 'type: chore', + 'refactor:': 'type: chore', + }; + for (const [prefix, label] of Object.entries(labelMapping)) { + if (title.startsWith(prefix)) { + const issue_number = context.payload.issue ? context.issue.number : context.payload.pull_request.number; + github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + labels: [label], + }); + break; + } + } From c61d23cd010045596b7e627fb36ed49e0305fd99 Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:01:37 +0800 Subject: [PATCH 02/10] chore: gi automations --- .github/workflows/auto-assign-author.yml | 4 ++-- .../auto-label-conventional-commits.yaml | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/auto-assign-author.yml b/.github/workflows/auto-assign-author.yml index 1a120e67f..69822f994 100644 --- a/.github/workflows/auto-assign-author.yml +++ b/.github/workflows/auto-assign-author.yml @@ -3,11 +3,11 @@ name: "Auto Author Assign" on: pull_request: types: [opened] -permissions: - pull-requests: write jobs: assign-author: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - uses: toshimaru/auto-author-assign@v1.1.0 with: diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index 13745d25b..30c85e965 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -4,19 +4,21 @@ on: types: [opened] pull_request: types: [opened] - -permissions: - issues: write - pull-requests: write - jobs: label_issues: runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write steps: - - name: Label issue - uses: actions/github-script@v5 + - uses: actions/labeler@v4 with: script: | + const github = require('@actions/github'); + const core = require('@actions/core'); + const token = core.getInput('github-token', { required: true }); + const octokit = github.getOctokit(token); + const title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title; const labelMapping = { 'feat:': 'type: feature request', @@ -33,7 +35,7 @@ jobs: for (const [prefix, label] of Object.entries(labelMapping)) { if (title.startsWith(prefix)) { const issue_number = context.payload.issue ? context.issue.number : context.payload.pull_request.number; - github.issues.addLabels({ + octokit.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue_number, From 34d3846e06f7abfbecf8736cad975331bd35310f Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:04:01 +0800 Subject: [PATCH 03/10] nits --- .github/workflows/auto-assign-author.yml | 2 +- .github/workflows/auto-label-conventional-commits.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-assign-author.yml b/.github/workflows/auto-assign-author.yml index 69822f994..0e861df00 100644 --- a/.github/workflows/auto-assign-author.yml +++ b/.github/workflows/auto-assign-author.yml @@ -1,5 +1,5 @@ # Auto assign author, tags, and reviewers to pull requests -name: "Auto Author Assign" +name: "Auto Assign Author" on: pull_request: types: [opened] diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index 30c85e965..a2ac27452 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -11,7 +11,7 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/labeler@v4 + - uses: actions/github-script@v5 with: script: | const github = require('@actions/github'); From 0b5fd341379d900214631278f9dc28bcc154fcda Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:15:54 +0800 Subject: [PATCH 04/10] try gh --- .../auto-label-conventional-commits.yaml | 61 ++++++++----------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index a2ac27452..a1f7135fd 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -1,9 +1,11 @@ name: "Auto Label Conventional Commits" on: issues: - types: [opened] + - reopened + - opened pull_request: - types: [opened] + - reopened + - opened jobs: label_issues: runs-on: ubuntu-latest @@ -11,36 +13,25 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/github-script@v5 - with: - script: | - const github = require('@actions/github'); - const core = require('@actions/core'); - const token = core.getInput('github-token', { required: true }); - const octokit = github.getOctokit(token); - - const title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title; - const labelMapping = { - 'feat:': 'type: feature request', - 'perf:': 'type: enhancement', - 'fix:': 'type: bug', - 'docs:': 'type: documentation', - 'ci:': 'type: ci', - 'build:': 'type: ci', - 'chore:': 'type: chore', - 'test:': 'type: chore', - 'style:': 'type: chore', - 'refactor:': 'type: chore', - }; - for (const [prefix, label] of Object.entries(labelMapping)) { - if (title.startsWith(prefix)) { - const issue_number = context.payload.issue ? context.issue.number : context.payload.pull_request.number; - octokit.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue_number, - labels: [label], - }); - break; - } - } + - name: Label issues + run: | + ISSUE_TITLE=$(gh issue view ${{ github.event.issue.number }} --json title -q ".title") + if [[ $ISSUE_TITLE == chore* ]]; then + gh issue edit ${{ github.event.issue.number }} --add-label "type: chore" + elif [[ $ISSUE_TITLE == feat* ]]; then + gh issue edit ${{ github.event.issue.number }} --add-label "type: feat" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# const labelMapping = { +# 'feat:': 'type: feature request', +# 'perf:': 'type: enhancement', +# 'fix:': 'type: bug', +# 'docs:': 'type: documentation', +# 'ci:': 'type: ci', +# 'build:': 'type: ci', +# 'chore:': 'type: chore', +# 'test:': 'type: chore', +# 'style:': 'type: chore', +# 'refactor:': 'type: chore', +# }; From 89cfb693517cc9113c0d4e07bb817cd0a1139b9b Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:21:24 +0800 Subject: [PATCH 05/10] fix types --- .github/workflows/auto-label-conventional-commits.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index a1f7135fd..c3f099ef7 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -1,11 +1,13 @@ name: "Auto Label Conventional Commits" on: issues: - - reopened - - opened + types: + - reopened + - opened pull_request: - - reopened - - opened + types: + - reopened + - opened jobs: label_issues: runs-on: ubuntu-latest From 13a403f3ec9ea3953abcf843c182de1637b160a6 Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:26:00 +0800 Subject: [PATCH 06/10] fix issue ref --- .github/workflows/auto-label-conventional-commits.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index c3f099ef7..6427be40b 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -17,11 +17,11 @@ jobs: steps: - name: Label issues run: | - ISSUE_TITLE=$(gh issue view ${{ github.event.issue.number }} --json title -q ".title") - if [[ $ISSUE_TITLE == chore* ]]; then - gh issue edit ${{ github.event.issue.number }} --add-label "type: chore" + ISSUE_TITLE=$(gh issue view "$NUMBER" --json title -q ".title") + if [[ $ISSUE_TITLE == chore:* ]]; then + gh issue edit "$NUMBER" --add-label "type: chore" elif [[ $ISSUE_TITLE == feat* ]]; then - gh issue edit ${{ github.event.issue.number }} --add-label "type: feat" + gh issue edit "$NUMBER" --add-label "type: feat" fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 347cb62b63804e91429a0fce92a581d68735b450 Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:35:04 +0800 Subject: [PATCH 07/10] fix --- .github/workflows/auto-label-conventional-commits.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index 6427be40b..f752fa4a3 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -17,11 +17,11 @@ jobs: steps: - name: Label issues run: | - ISSUE_TITLE=$(gh issue view "$NUMBER" --json title -q ".title") + ISSUE_TITLE=$(gh issue view ${{ github.event.number }} --json title -q ".title") if [[ $ISSUE_TITLE == chore:* ]]; then - gh issue edit "$NUMBER" --add-label "type: chore" - elif [[ $ISSUE_TITLE == feat* ]]; then - gh issue edit "$NUMBER" --add-label "type: feat" + gh issue edit ${{ github.event.number }} --add-label "type: chore" + elif [[ $ISSUE_TITLE == feat:* ]]; then + gh issue edit ${{ github.event.number }} --add-label "type: feat" fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e3b39819c6d256cd67724f4dd6c1efc6973d081a Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:42:23 +0800 Subject: [PATCH 08/10] checkout repo --- .github/workflows/auto-label-conventional-commits.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index f752fa4a3..d7ff94662 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -8,6 +8,7 @@ on: types: - reopened - opened + - edited jobs: label_issues: runs-on: ubuntu-latest @@ -15,6 +16,8 @@ jobs: issues: write pull-requests: write steps: + - name: Checkout + uses: actions/checkout@v4 - name: Label issues run: | ISSUE_TITLE=$(gh issue view ${{ github.event.number }} --json title -q ".title") From d489357da06d2a8eb179f1e6e9317f773e99226b Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:51:05 +0800 Subject: [PATCH 09/10] add all labels --- .../auto-label-conventional-commits.yaml | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index d7ff94662..9fe9a39ea 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -21,22 +21,21 @@ jobs: - name: Label issues run: | ISSUE_TITLE=$(gh issue view ${{ github.event.number }} --json title -q ".title") - if [[ $ISSUE_TITLE == chore:* ]]; then - gh issue edit ${{ github.event.number }} --add-label "type: chore" - elif [[ $ISSUE_TITLE == feat:* ]]; then - gh issue edit ${{ github.event.number }} --add-label "type: feat" + case "$ISSUE_TITLE" in + chore:*) LABEL="type: chore" ;; + feat:*) LABEL="type: feature request" ;; + perf:*) LABEL="type: enhancement" ;; + fix:*) LABEL="type: bug" ;; + docs:*) LABEL="type: documentation" ;; + ci:*) LABEL="type: ci" ;; + build:*) LABEL="type: ci" ;; + test:*) LABEL="type: chore" ;; + style:*) LABEL="type: chore" ;; + refactor:*) LABEL="type: chore" ;; + *) LABEL="" ;; + esac + if [ -n "$LABEL" ]; then + gh issue edit ${{ github.event.number }} --add-label "$LABEL" fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# const labelMapping = { -# 'feat:': 'type: feature request', -# 'perf:': 'type: enhancement', -# 'fix:': 'type: bug', -# 'docs:': 'type: documentation', -# 'ci:': 'type: ci', -# 'build:': 'type: ci', -# 'chore:': 'type: chore', -# 'test:': 'type: chore', -# 'style:': 'type: chore', -# 'refactor:': 'type: chore', -# }; From 1c765390bbeef792838d3f65746be3826a391384 Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 1 Dec 2023 14:51:52 +0800 Subject: [PATCH 10/10] remove edited trigger --- .github/workflows/auto-label-conventional-commits.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index 9fe9a39ea..7e6e19a66 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -8,7 +8,6 @@ on: types: - reopened - opened - - edited jobs: label_issues: runs-on: ubuntu-latest