Merge pull request #175 from BitGo/DX-2592-breaking-changes-linting #56
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 to GHCR | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| inputs: | |
| commit_sha: | |
| description: 'Git commit SHA to build and deploy' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write # Needed to create new releases | |
| packages: write # Needed to push to GHCR | |
| id-token: write # Needed to create an ephemeral cross-repo token | |
| jobs: | |
| get-context: | |
| name: Generate release context | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new-version: ${{ steps.compute-context.outputs.new-version }} | |
| current-version: ${{ steps.compute-context.outputs.current-version }} | |
| version-changed: ${{ steps.compute-context.outputs.version-changed }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.commit_sha || github.sha }} | |
| fetch-depth: 0 # Fetch all history for git describe to work | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Compute the context for this release | |
| id: compute-context | |
| run: | | |
| current_version=$(cat package.json | jq -r .version) | |
| # Check if the version in package.json is using semantic versioning | |
| if [[ "$current_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Current version is a valid semantic version: $current_version" | |
| else | |
| echo "Current version format is not a standard semantic version: $current_version" | |
| exit 1 | |
| fi | |
| echo "current-version=$current_version" >> "$GITHUB_OUTPUT" | |
| # Check if the version in package.json was changed in the last commit | |
| previous_commit=$(git rev-parse HEAD~1) | |
| previous_version=$(git show $previous_commit:package.json 2>/dev/null | jq -r .version || echo "") | |
| echo "Previous version: $previous_version" | |
| echo "Current version: $current_version" | |
| if [ "$current_version" != "$previous_version" ] && [[ "$current_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Version changed from $previous_version to $current_version in the last commit" | |
| echo "version-changed=true" >> $GITHUB_OUTPUT | |
| echo "new-version=$current_version" >> $GITHUB_OUTPUT | |
| elif [ -n "${{ github.event.inputs.commit_sha }}" ] && [[ "$current_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Workflow was manually triggered, trying to publish $current_version" | |
| echo "version-changed=true" >> $GITHUB_OUTPUT | |
| echo "new-version=$current_version" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version unchanged or not following semantic versioning format" | |
| echo "version-changed=false" >> $GITHUB_OUTPUT | |
| echo "new-version=$current_version" >> $GITHUB_OUTPUT | |
| fi | |
| create-release: | |
| name: Create GitHub release | |
| needs: get-context | |
| if: ${{ needs.get-context.outputs.version-changed == 'true' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release-id: ${{ steps.create-release.outputs.id }} | |
| release-url: ${{ steps.create-release.outputs.html_url }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.commit_sha || github.sha }} | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Generate release notes | |
| id: generate-notes | |
| run: | | |
| # Generate release notes using the existing .releaserc.json configuration | |
| notes=$(npx semantic-release --dry-run --no-ci --plugins @semantic-release/release-notes-generator 2>/dev/null | grep -A 1000 "Release note for version" | tail -n +2) | |
| echo "notes<<EOF" >> $GITHUB_OUTPUT | |
| echo "$notes" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create release | |
| id: create-release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const release = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: `v${process.env.VERSION}`, | |
| name: `v${process.env.VERSION}`, | |
| body: process.env.RELEASE_NOTES, | |
| draft: false, | |
| prerelease: false | |
| }); | |
| return release.data; | |
| env: | |
| VERSION: ${{ needs.get-context.outputs.new-version }} | |
| RELEASE_NOTES: ${{ steps.generate-notes.outputs.notes }} | |
| build-and-push: | |
| name: Build and push image to GHCR | |
| needs: [get-context, create-release] | |
| if: ${{ needs.get-context.outputs.version-changed == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.commit_sha || github.sha }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/bitgo/advanced-wallets:${{ needs.get-context.outputs.new-version }} | |
| ghcr.io/bitgo/advanced-wallets:latest | |
| build-args: | | |
| BUILD_VERSION=${{ needs.get-context.outputs.new-version }} | |
| BUILD_DATE=${{ github.event.repository.updated_at }} | |
| VCS_REF=${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |