chore(release): prepare release v1.21.0 #28
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Process | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| type: | |
| type: choice | |
| description: Choose release type | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| default: patch | |
| beta: | |
| type: boolean | |
| description: Prerelease | |
| default: false | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| # This job prepares a release PR | |
| prepare-release: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: git config | |
| run: | | |
| git config user.name "${GITHUB_ACTOR}" | |
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| - name: Setup node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - run: npm ci | |
| # Prepare the version change and update files | |
| - name: Prepare release changes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TYPE_ARG: ${{ inputs.type }} | |
| BETA_ARG: ${{ inputs.beta == true && '--preRelease=beta' || '' }} | |
| run: | | |
| # First, get the current version | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| # Run release-it to get the new version information, but don't make changes | |
| NEW_VERSION_INFO=$(npm run release -- $TYPE_ARG --ci --verbose --no-git.push --no-git.commit --no-git.tag --no-github --no-npm $BETA_ARG --dry-run) | |
| # Extract the new version from the output | |
| NEW_VERSION=$(echo "$NEW_VERSION_INFO" | grep -o "Let's release docker-to-iac ([^)]*)" | sed 's/.*\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/') | |
| echo "Current version: $CURRENT_VERSION" | |
| echo "New version: $NEW_VERSION" | |
| # Update package.json with the new version | |
| sed -i "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" package.json | |
| # Extract the changelog from dry run output and save it | |
| CHANGELOG=$(echo "$NEW_VERSION_INFO" | sed -n '/^Changelog:/,/^\$ npm run build/p' | grep -v '^\$ npm run build' | grep -v '^\$ ' | grep -v '^!' | grep -v 'Done') | |
| # Format the changelog - remove 'Changelog:' line and ensure we use ## for version headers | |
| CHANGELOG=$(echo "$CHANGELOG" | sed '1d' | sed "s/# \[$NEW_VERSION\]/## \[$NEW_VERSION\]/") | |
| # Get the existing changelog content | |
| EXISTING_CHANGELOG=$(cat CHANGELOG.md) | |
| # Check if changelog already has the new version header | |
| if ! grep -q "## \[$NEW_VERSION\]" CHANGELOG.md; then | |
| # Insert the new changelog after the header | |
| echo -e "# Changelog\n\n$CHANGELOG\n$(echo "$EXISTING_CHANGELOG" | tail -n +2)" > CHANGELOG.md | |
| fi | |
| # No need to run release-it again - we've already updated version and changelog | |
| echo "Version and changelog updated successfully!" | |
| # Also run the build to ensure everything is up to date | |
| npm run build | |
| # Get the version from package.json (which should now be updated) | |
| - name: Get version | |
| id: package-version | |
| uses: martinbeentjes/npm-get-version-action@main | |
| # Create a branch with the changes and push it | |
| - name: Create and push branch | |
| run: | | |
| # Get the new version that was prepared | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "New version is: $NEW_VERSION" | |
| # Create a new branch using the NEW_VERSION | |
| BRANCH_NAME="release-v$NEW_VERSION" | |
| git checkout -b $BRANCH_NAME | |
| # Add the changes | |
| git add . | |
| git commit -m "chore(release): prepare release v$NEW_VERSION" | |
| git push origin $BRANCH_NAME | |
| # Output the PR creation URL to the logs | |
| echo "::notice::✅ Branch created and pushed: $BRANCH_NAME" | |
| echo "::notice::⚠️ You must manually create a PR from this branch at this URL:" | |
| echo "::notice::➡️ https://github.com/${{ github.repository }}/compare/main...$BRANCH_NAME?expand=1" | |
| echo "::notice::📝 Important: Add the 'release' label to your PR for the release workflow to run when merged" | |
| # Also output to step summary for better visibility | |
| echo "# Release Branch Created" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The release branch has been created and pushed as: \`$BRANCH_NAME\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Next Steps" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "1. [Create a pull request](https://github.com/${{ github.repository }}/compare/main...$BRANCH_NAME?expand=1) from this branch" >> $GITHUB_STEP_SUMMARY | |
| echo "2. Add the 'release' label to your PR" >> $GITHUB_STEP_SUMMARY | |
| echo "3. Get the PR reviewed and merged" >> $GITHUB_STEP_SUMMARY | |
| echo "4. Once merged, the release will automatically be published" >> $GITHUB_STEP_SUMMARY | |
| # This job performs the actual release after a PR has been merged | |
| publish-release: | |
| if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: git config | |
| run: | | |
| git config user.name "${GITHUB_ACTOR}" | |
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| - name: Setup node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| registry-url: 'https://registry.npmjs.org' | |
| - run: npm ci | |
| # Create the tag and GitHub release | |
| - name: Create GitHub release tag | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Create a tag for the version | |
| VERSION=$(node -p "require('./package.json').version") | |
| git tag -a "v$VERSION" -m "Release v$VERSION" | |
| git push origin "v$VERSION" | |
| # Extract changelog entries for this version | |
| CHANGELOG_ENTRY=$(awk "/## \\[$VERSION\\]/,/## \\[/ { if (!/## \\[$VERSION\\]/ && /## \\[/) exit; print }" CHANGELOG.md) | |
| # Create GitHub release | |
| gh release create "v$VERSION" --title "v$VERSION" --notes "$CHANGELOG_ENTRY" | |
| # Publish to npm | |
| - name: Publish to npm | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| # Publish the package to npm | |
| npm publish --access public |