diff --git a/.github/workflows/pr-release-validation.yaml b/.github/workflows/pr-release-validation.yaml new file mode 100644 index 00000000..99c57037 --- /dev/null +++ b/.github/workflows/pr-release-validation.yaml @@ -0,0 +1,31 @@ +name: PR Validation + +on: + pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] + branches: + - main + +jobs: + validate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Validate PR Labels + run: | + if [[ "${{ contains(github.event.pull_request.labels.*.name, 'stable-release') }}" == "true" ]]; then + echo "✓ PR has stable-release label" + + # Check version bump labels + if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then + echo "✓ Major version bump requested" + elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then + echo "✓ Minor version bump requested" + else + echo "✓ Patch version bump will be applied" + fi + else + echo "This PR doesn't have the stable-release label. No release will be created." + fi \ No newline at end of file diff --git a/.github/workflows/update-stable.yml b/.github/workflows/update-stable.yml index fa8be6ab..54825e4a 100644 --- a/.github/workflows/update-stable.yml +++ b/.github/workflows/update-stable.yml @@ -1,8 +1,7 @@ name: Update Stable Branch on: - pull_request: - types: [closed] + push: branches: - main @@ -10,18 +9,15 @@ permissions: contents: write jobs: - update-stable: - if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'stable-release') + prepare-release: + if: contains(github.event.head_commit.message, '#release') runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: read steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} + - name: Configure Git run: | git config --global user.name 'github-actions[bot]' @@ -52,17 +48,6 @@ jobs: restore-keys: | ${{ runner.os }}-pnpm-store- - - name: Determine Version Bump - id: version_bump - run: | - if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then - echo "bump=major" >> $GITHUB_OUTPUT - elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then - echo "bump=minor" >> $GITHUB_OUTPUT - else - echo "bump=patch" >> $GITHUB_OUTPUT - fi - - name: Get Current Version id: current_version run: | @@ -72,6 +57,18 @@ jobs: - name: Install semver run: pnpm add -g semver + - name: Determine Version Bump + id: version_bump + run: | + COMMIT_MSG="${{ github.event.head_commit.message }}" + if [[ $COMMIT_MSG =~ "#release:major" ]]; then + echo "bump=major" >> $GITHUB_OUTPUT + elif [[ $COMMIT_MSG =~ "#release:minor" ]]; then + echo "bump=minor" >> $GITHUB_OUTPUT + else + echo "bump=patch" >> $GITHUB_OUTPUT + fi + - name: Bump Version id: bump_version run: | @@ -161,32 +158,30 @@ jobs: echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - - name: Commit Version Update + - name: Commit and Tag Release run: | git pull git add package.json pnpm-lock.yaml changelog.md - git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new_version }}" + git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}" + git tag "v${{ steps.bump_version.outputs.new_version }}" git push + git push --tags - name: Update Stable Branch run: | - # Ensure stable branch exists - git checkout stable 2>/dev/null || git checkout -b stable - git merge main --no-ff -m "chore: merge main into stable for version ${{ steps.bump_version.outputs.new_version }}" - git push --set-upstream origin stable + if ! git checkout stable 2>/dev/null; then + echo "Creating new stable branch..." + git checkout -b stable + fi + git merge main --no-ff -m "chore: release version ${{ steps.bump_version.outputs.new_version }}" + git push --set-upstream origin stable --force - - name: Create and Push Tag + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | VERSION="v${{ steps.bump_version.outputs.new_version }}" - git tag -a "$VERSION" -m "Release $VERSION" - git push origin "$VERSION" - - # - name: Create GitHub Release - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # run: | - # VERSION="v${{ steps.bump_version.outputs.new_version }}" - # gh release create "$VERSION" \ - # --title "Release $VERSION" \ - # --notes "${{ steps.changelog.outputs.content }}" \ - # --target stable \ No newline at end of file + gh release create "$VERSION" \ + --title "Release $VERSION" \ + --notes "${{ steps.changelog.outputs.content }}" \ + --target stable \ No newline at end of file