Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions .github/workflows/release-to-ghcr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
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: 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
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: 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: 'Automated release created by GitHub Actions',
draft: false,
prerelease: false,
generate_release_notes: true
});
return release.data;
env:
VERSION: ${{ needs.get-context.outputs.new-version }}

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: "${{ needs.get-context.outputs.new-version }},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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitgo/advanced-wallets",
"version": "0.0.0-semantically-released",
"version": "0.0.1",
"description": "Advanced Wallets - On-Premises Key Management with BitGo Express",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down