Create Release & Publish #26
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: Create Release & Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: 'Version type' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| new_version: ${{ steps.new-version.outputs.new_version }} | |
| branch_name: ${{ steps.new-version.outputs.branch_name }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| # ACTIONS_TOKEN required to push to protected main branch | |
| token: ${{ secrets.ACTIONS_TOKEN || github.token }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: '24' | |
| - name: Get current version | |
| id: current-version | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| - name: Calculate new version | |
| id: new-version | |
| run: | | |
| CURRENT_VERSION="${{ steps.current-version.outputs.current_version }}" | |
| VERSION_TYPE="${{ inputs.version_type }}" | |
| IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" | |
| case "$VERSION_TYPE" in | |
| major) | |
| major=$((major + 1)) | |
| minor=0 | |
| patch=0 | |
| ;; | |
| minor) | |
| minor=$((minor + 1)) | |
| patch=0 | |
| ;; | |
| patch) | |
| patch=$((patch + 1)) | |
| ;; | |
| esac | |
| NEW_VERSION="${major}.${minor}.${patch}" | |
| BRANCH_NAME="release/${NEW_VERSION}" | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| echo "New version: $NEW_VERSION" | |
| echo "Branch name: $BRANCH_NAME" | |
| - name: Check if branch already exists | |
| run: | | |
| BRANCH_NAME="${{ steps.new-version.outputs.branch_name }}" | |
| # Check if branch exists locally or remotely | |
| if git show-ref --verify --quiet refs/heads/$BRANCH_NAME || git show-ref --verify --quiet refs/remotes/origin/$BRANCH_NAME; then | |
| echo "❌ Branch $BRANCH_NAME already exists" | |
| exit 1 | |
| else | |
| echo "✅ Branch $BRANCH_NAME does not exist, proceeding..." | |
| fi | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Update main branch version | |
| run: | | |
| CURRENT_VERSION="${{ steps.current-version.outputs.current_version }}" | |
| NEW_VERSION="${{ steps.new-version.outputs.new_version }}" | |
| echo "Updating main branch version from $CURRENT_VERSION to $NEW_VERSION" | |
| # Update version in package.json | |
| npm version "$NEW_VERSION" --no-git-tag-version | |
| # Commit and push to main | |
| git add package.json | |
| git commit -m "Release v$NEW_VERSION" | |
| git push origin main | |
| - name: Create release branch | |
| run: | | |
| BRANCH_NAME="${{ steps.new-version.outputs.branch_name }}" | |
| echo "Creating release branch: $BRANCH_NAME" | |
| # Create new branch from updated main | |
| git checkout -b "$BRANCH_NAME" | |
| # Push the release branch | |
| git push origin "$BRANCH_NAME" | |
| echo "✅ Release branch created: $BRANCH_NAME" | |
| create-tag: | |
| needs: create-release | |
| permissions: | |
| contents: write | |
| uses: ./.github/workflows/tag-release.yml | |
| with: | |
| branch_ref: ${{ needs.create-release.outputs.branch_name }} | |
| secrets: inherit | |
| create-summary: | |
| needs: [create-release, create-tag] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Create summary | |
| run: | | |
| echo "## 🚀 Release Created" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ needs.create-tag.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Tag:** \`${{ needs.create-tag.outputs.tag_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Branch:** \`${{ needs.create-release.outputs.branch_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Type:** ${{ inputs.version_type }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Release URL:** ${{ needs.create-tag.outputs.release_url }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Next Steps" >> $GITHUB_STEP_SUMMARY | |
| echo "The npm package will be automatically published when the release branch is pushed." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Monitor the publish workflow: [View Workflows](https://github.com/RoboFinSystems/robosystems-core/actions/workflows/publish.yml)" >> $GITHUB_STEP_SUMMARY |