Skip to content

Commit 1bd46d0

Browse files
committed
feat: create ghcr release workflow
TICKET: VL-3317
1 parent 2b75146 commit 1bd46d0

2 files changed

Lines changed: 120 additions & 1 deletion

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
name: Release to GHCR
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
9+
permissions:
10+
contents: write # Needed to create new releases
11+
packages: write # Needed to push to GHCR
12+
id-token: write # Needed to create an ephemeral cross-repo token
13+
14+
jobs:
15+
get-context:
16+
name: Generate release context
17+
runs-on: ubuntu-latest
18+
outputs:
19+
new-version: ${{ steps.compute-context.outputs.new-version }}
20+
current-version: ${{ steps.compute-context.outputs.current-version }}
21+
version-changed: ${{ steps.compute-context.outputs.version-changed }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.sha }}
27+
fetch-depth: 0 # Fetch all history for git describe to work
28+
29+
- name: Compute the context for this release
30+
id: compute-context
31+
run: |
32+
current_version=$(cat package.json | jq -r .version)
33+
34+
# Check if the version in package.json is using semantic versioning
35+
if [[ "$current_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
36+
echo "Current version is a valid semantic version: $current_version"
37+
else
38+
echo "Current version format is not a standard semantic version: $current_version"
39+
exit 1
40+
fi
41+
42+
echo "current-version=$current_version" >> "$GITHUB_OUTPUT"
43+
44+
# Check if the version in package.json was changed in the last commit
45+
previous_commit=$(git rev-parse HEAD~1)
46+
previous_version=$(git show $previous_commit:package.json 2>/dev/null | jq -r .version || echo "")
47+
48+
echo "Previous version: $previous_version"
49+
echo "Current version: $current_version"
50+
51+
if [ "$current_version" != "$previous_version" ] && [[ "$current_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
52+
echo "Version changed from $previous_version to $current_version in the last commit"
53+
echo "version-changed=true" >> $GITHUB_OUTPUT
54+
echo "new-version=$current_version" >> $GITHUB_OUTPUT
55+
else
56+
echo "Version unchanged or not following semantic versioning format"
57+
echo "version-changed=false" >> $GITHUB_OUTPUT
58+
echo "new-version=$current_version" >> $GITHUB_OUTPUT
59+
fi
60+
61+
create-release:
62+
name: Create GitHub release
63+
needs: get-context
64+
if: ${{ needs.get-context.outputs.version-changed == 'true' }}
65+
runs-on: ubuntu-latest
66+
outputs:
67+
release-id: ${{ steps.create-release.outputs.id }}
68+
release-url: ${{ steps.create-release.outputs.html_url }}
69+
steps:
70+
- name: Create release
71+
id: create-release
72+
uses: actions/github-script@v7
73+
with:
74+
script: |
75+
const release = await github.rest.repos.createRelease({
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
tag_name: `v${process.env.VERSION}`,
79+
name: `v${process.env.VERSION}`,
80+
body: 'Automated release created by GitHub Actions',
81+
draft: false,
82+
prerelease: false,
83+
generate_release_notes: true
84+
});
85+
return release.data;
86+
env:
87+
VERSION: ${{ needs.get-context.outputs.new-version }}
88+
89+
build-and-push:
90+
name: Build and push image to GHCR
91+
needs: [get-context, create-release]
92+
if: ${{ needs.get-context.outputs.version-changed == 'true' }}
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@v4
97+
98+
- name: Set up Docker Buildx
99+
uses: docker/setup-buildx-action@v3
100+
101+
- name: Login to GitHub Container Registry
102+
uses: docker/login-action@v3
103+
with:
104+
registry: ghcr.io
105+
username: ${{ github.actor }}
106+
password: ${{ secrets.GITHUB_TOKEN }}
107+
108+
- name: Build and push Docker image
109+
uses: docker/build-push-action@v6
110+
with:
111+
context: .
112+
push: true
113+
tags: "${{ needs.get-context.outputs.new-version }},latest"
114+
build-args: |
115+
BUILD_VERSION=${{ needs.get-context.outputs.new-version }}
116+
BUILD_DATE=${{ github.event.repository.updated_at }}
117+
VCS_REF=${{ github.sha }}
118+
cache-from: type=gha
119+
cache-to: type=gha,mode=max

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitgo/advanced-wallets",
3-
"version": "0.0.0-semantically-released",
3+
"version": "0.0.1",
44
"description": "Advanced Wallets - On-Premises Key Management with BitGo Express",
55
"main": "./dist/src/index.js",
66
"types": "./dist/src/index.d.ts",

0 commit comments

Comments
 (0)