diff --git a/.github/workflows/pr-title.yaml b/.github/workflows/pr-title.yaml new file mode 100644 index 0000000..9ec553f --- /dev/null +++ b/.github/workflows/pr-title.yaml @@ -0,0 +1,48 @@ +name: 'Validate PR title' + +on: + workflow_call: + +jobs: + main: + name: Validate PR title + runs-on: ubuntu-latest + steps: + # Please look up the latest version from + # https://github.com/amannn/action-semantic-pull-request/releases + - uses: amannn/action-semantic-pull-request@v6.1.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # Configure which types are allowed. + # Default: https://github.com/commitizen/conventional-commit-types + types: | + fix + feat + docs + ci + chore + # Configure that a scope must always be provided. + requireScope: false + # Configure additional validation for the subject based on a regex. + # This example ensures the subject starts with an uppercase character. + subjectPattern: ^[A-Z].+$ + # If `subjectPattern` is configured, you can use this property to override + # the default error message that is shown when the pattern doesn't match. + # The variables `subject` and `title` can be used within the message. + subjectPatternError: | + The subject "{subject}" found in the pull request title "{title}" + didn't match the configured pattern. Please ensure that the subject + starts with an uppercase character. + # For work-in-progress PRs you can typically use draft pull requests + # from Github. However, private repositories on the free plan don't have + # this option and therefore this action allows you to opt-in to using the + # special "[WIP]" prefix to indicate this state. This will avoid the + # validation of the PR title and the pull request checks remain pending. + # Note that a second check will be reported if this is enabled. + wip: true + # When using "Squash and merge" on a PR with only one commit, GitHub + # will suggest using that commit message instead of the PR title for the + # merge commit, and it's easy to commit this by mistake. Enable this option + # to also validate the commit message for one commit PRs. + validateSingleCommit: false diff --git a/.github/workflows/release-preview.yaml b/.github/workflows/release-preview.yaml new file mode 100644 index 0000000..cc5ce4b --- /dev/null +++ b/.github/workflows/release-preview.yaml @@ -0,0 +1,118 @@ +name: Release Preview + +on: + workflow_call: + +env: + SEMANTIC_RELEASE_VERSION: '24.2.0' + NODE_VERSION: '20.11.0' + +jobs: + preview: + name: Preview Release + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Run semantic-release (dry-run) + id: semantic + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GIT_COMMITTER_NAME: "github-actions[bot]" + GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com" + GIT_AUTHOR_NAME: "github-actions[bot]" + GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com" + run: | + # Unset GitHub Actions environment variables that interfere with semantic-release + unset GITHUB_REF + unset GITHUB_REF_NAME + unset GITHUB_HEAD_REF + unset GITHUB_BASE_REF + + # Set them to what we want + export GITHUB_REF="refs/heads/${{ github.event.pull_request.head.ref }}" + export GITHUB_REF_NAME="${{ github.event.pull_request.head.ref }}" + + # Run semantic-release with inline configuration using CLI options + OUTPUT=$(npx --package semantic-release@${{ env.SEMANTIC_RELEASE_VERSION }} \ + --package @semantic-release/exec \ + --package conventional-changelog-conventionalcommits \ + semantic-release \ + --dry-run \ + --no-ci \ + --debug \ + --branches ${{ github.event.pull_request.head.ref }} 2>&1 || true) + echo "$OUTPUT" + + # Extract version information + NEW_VERSION=$(echo "$OUTPUT" | grep -Eo "The next release version is [0-9]+\.[0-9]+\.[0-9]+" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+" || echo "") + RELEASE_TYPE=$(echo "$OUTPUT" | grep -Eo "Analysis of [0-9]+ commits complete: [a-z]+ release" | grep -Eo "(major|minor|patch) release" | sed 's/ release//' || echo "") + + # Extract release notes (everything after "Release note for version") + RELEASE_NOTES=$(echo "$OUTPUT" | sed -n '/Release note for version/,$p' | tail -n +2 || echo "") + + # Save to outputs + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT + + # Save release notes for comment + echo "release_notes<> $GITHUB_OUTPUT + echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Display Preview + run: | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo " RELEASE PREVIEW" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo "" + if [ -n "${{ steps.semantic.outputs.new_version }}" ]; then + echo "Version: v${{ steps.semantic.outputs.new_version }}" + echo "Release Type: ${{ steps.semantic.outputs.release_type }}" + echo "Status: Release will be published" + else + echo "Status: No release will be published" + echo "Reason: No relevant changes detected" + fi + echo "" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + + - name: Comment on PR + if: github.event_name == 'pull_request' + uses: mshick/add-pr-comment@v2 + with: + message-id: release-preview + message: | + ## Release Preview + + ${{ steps.semantic.outputs.new_version && format('**Version:** `v{0}` + **Release Type:** `{1}` + **Status:** Release will be published when merged to main + + --- + + ### Release Notes + + {2} + + --- + + *This preview is generated by semantic-release dry-run mode*', steps.semantic.outputs.new_version, steps.semantic.outputs.release_type, steps.semantic.outputs.release_notes) || '**Status:** No release will be published + **Reason:** No relevant changes detected + + --- + + *This preview is generated by semantic-release dry-run mode*' }} diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 3c55029..a264739 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -15,6 +15,17 @@ on: - main - master jobs: + prTitlecheck: + name: PR title check + uses: ./.github/workflows/pr-title.yaml + + releasePreview: + name: Release Preview + uses: ./.github/workflows/release-preview.yaml + permissions: + contents: write + pull-requests: write + preCommitCheck: name: Terraform Checks uses: ./.github/workflows/terraform-checks.yaml