From 486d3d984937c708909671bbb145a846442ef7ed Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Fri, 5 Jul 2024 10:22:07 +0100 Subject: [PATCH] ci: Use hugrbot on CI --- .github/workflows/issue.yml | 69 --------------------- .github/workflows/pr-title.yml | 100 ++++++++++++++++++++++++++++-- .github/workflows/release-plz.yml | 7 ++- 3 files changed, 100 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/issue.yml diff --git a/.github/workflows/issue.yml b/.github/workflows/issue.yml deleted file mode 100644 index 279c09a..0000000 --- a/.github/workflows/issue.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: New issue - -on: - issues: - types: [opened] - -jobs: - jira_task: - name: Create Jira issue - runs-on: ubuntu-22.04 - steps: - - name: Login - uses: atlassian/gajira-login@v3.0.1 - env: - JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - - name: Parse the priority label into a Jira priority - id: set_priority_var - env: - LABELS: ${{ join(github.event.issue.labels.*.name, ' ') }} - run: | - MY_RESULT="" - for label in $LABELS - do - case $label in - P-low) - MY_RESULT=Low - break;; - P-medium) - MY_RESULT=Medium - break;; - P-high) - MY_RESULT=High - break;; - P-critical) - MY_RESULT=Highest - break;; - esac - done - if [ ! -z $MY_RESULT ] - then - MY_RESULT=", \"priority\": { \"name\": \"$MY_RESULT\" }" - fi - echo "JIRA_PRIORITY_FIELD=$MY_RESULT" >> $GITHUB_OUTPUT - - - name: Create Bug - uses: atlassian/gajira-create@v3.0.1 - if: ${{ contains(github.event.issue.labels.*.name, 'bug') }} - env: - JIRA_PRIORITY_FIELD: ${{ steps.set_priority_var.outputs.JIRA_PRIORITY_FIELD }} - with: - project: TKET - issuetype: Bug - summary: ยซ [tket-json-rs] ${{ github.event.issue.title }}ยป - description: ${{ github.event.issue.html_url }} - fields: '{ "labels": ["tket-json-rs"] ${{ env.JIRA_PRIORITY_FIELD }} }' - - - name: Create Task - uses: atlassian/gajira-create@v3.0.1 - if: ${{ ! contains(github.event.issue.labels.*.name, 'bug') }} - env: - JIRA_PRIORITY_FIELD: ${{ steps.set_priority_var.outputs.JIRA_PRIORITY_FIELD }} - with: - project: TKET - issuetype: Task - summary: ยซ [tket-json-rs] ${{ github.event.issue.title }}ยป - description: ${{ github.event.issue.html_url }} - fields: '{ "labels": ["tket-json-rs"] ${{ env.JIRA_PRIORITY_FIELD }} }' diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index 0a74226..8f640b4 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -3,7 +3,7 @@ name: Check Conventional Commits format on: pull_request_target: branches: - - main + - main types: - opened - edited @@ -14,7 +14,7 @@ on: types: [checks_requested] permissions: - pull-requests: read + pull-requests: write jobs: main: @@ -23,8 +23,15 @@ jobs: # The action does not support running on merge_group events, # but if the check succeeds in the PR there is no need to check it again. if: github.event_name == 'pull_request_target' + outputs: + # Whether the PR title indicates a breaking change. + breaking: ${{ steps.breaking.outputs.breaking }} + # Whether the PR body contains a "BREAKING CHANGE:" footer describing the breaking change. + has_breaking_footer: ${{ steps.breaking.outputs.has_breaking_footer }} steps: - - uses: amannn/action-semantic-pull-request@v5 + - name: Validate the PR title format + uses: amannn/action-semantic-pull-request@v5 + id: lint_pr_title env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -69,4 +76,89 @@ jobs: # labels change, you might want to use the `labeled` and `unlabeled` # event triggers in your workflow. ignoreLabels: | - ignore-semantic-pull-request \ No newline at end of file + ignore-semantic-pull-request + + # `action-semantic-pull-request` does not parse the title, so it cannot + # detect if it is marked as a breaking change. + # + # Since at this point we know the PR title is a valid conventional commit, + # we can use a simple regex that looks for a '!:' sequence. It could be + # more complex, but we don't care about false positives. + - name: Check for breaking change flag + id: breaking + run: | + if [[ "${PR_TITLE}" =~ ^.*\!:.*$ ]]; then + echo "breaking=true" >> $GITHUB_OUTPUT + else + echo "breaking=false" >> $GITHUB_OUTPUT + fi + + # Check if the PR comment has a "BREAKING CHANGE:" footer describing + # the breaking change. + if [[ "${PR_BODY}" != *"BREAKING CHANGE:"* ]]; then + echo "has_breaking_footer=false" >> $GITHUB_OUTPUT + else + echo "has_breaking_footer=true" >> $GITHUB_OUTPUT + fi + env: + PR_TITLE: ${{ github.event.pull_request.title }} + PR_BODY: ${{ github.event.pull_request.body }} + + # Post a help comment if the PR title indicates a breaking change but does + # not contain a "BREAKING CHANGE:" footer. + - name: Require "BREAKING CHANGE:" footer for breaking changes + id: breaking-comment + if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: pr-title-lint-error + message: | + Hey there and thank you for opening this pull request! ๐Ÿ‘‹๐Ÿผ + + It looks like your proposed title indicates a breaking change. If that's the case, + please make sure to include a "BREAKING CHANGE:" footer in the body of the pull request + describing the breaking change and any migration instructions. + GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }} + - name: Fail if the footer is required but missing + if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }} + run: exit 1 + + - name: Post a comment if the PR badly formatted + uses: marocchino/sticky-pull-request-comment@v2 + # When the previous steps fails, the workflow would stop. By adding this + # condition you can continue the execution with the populated error message. + if: always() && (steps.lint_pr_title.outputs.error_message != null) + with: + header: pr-title-lint-error + message: | + Hey there and thank you for opening this pull request! ๐Ÿ‘‹๐Ÿผ + + We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) + and it looks like your proposed title needs to be adjusted. + + Your title should look like this. The scope field is optional. + ``` + (): + ``` + + If the PR includes a breaking change, mark it with an exclamation mark: + ``` + !: + ``` + and include a "BREAKING CHANGE:" footer in the body of the pull request. + + Details: + ``` + ${{ steps.lint_pr_title.outputs.error_message }} + ``` + GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }} + + + # Delete previous comments when the issues have been resolved + # This step doesn't run if any of the previous checks fails. + - name: Delete previous comments + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: pr-title-lint-error + delete: true + GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }} diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index 85bd88f..9b1d2b5 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -1,4 +1,5 @@ -name: Release-plz +# Automatic changelog, version bumping, and semver-checks with release-plz for rust projects +name: Release-plz ๐Ÿฆ€ permissions: pull-requests: write @@ -23,5 +24,5 @@ jobs: - name: Run release-plz uses: MarcoIeni/release-plz-action@v0.5 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}