Skip to content

Commit c69cbb1

Browse files
chore: publish_github_package.yml
1 parent 8c3b5a2 commit c69cbb1

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Publish Docker image to GitHub packages
2+
3+
permissions:
4+
contents: read
5+
packages: write
6+
7+
on:
8+
push:
9+
tags:
10+
- '*'
11+
workflow_dispatch:
12+
13+
env:
14+
GITHUB_REPO: ghcr.io/${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- platform: linux/amd64
23+
runner: ubuntu-latest
24+
- platform: linux/arm64
25+
runner: ubuntu-22.04-arm
26+
runs-on: ${{ matrix.runner }}
27+
env:
28+
GIT_REF: ${{ github.head_ref || github.ref_name }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Update package.json version
34+
if: startsWith(github.ref, 'refs/tags/')
35+
run: |
36+
TAG_VERSION=${GITHUB_REF#refs/tags/}
37+
echo "Updating package.json version to $TAG_VERSION"
38+
npm version "$TAG_VERSION" --no-git-tag-version
39+
40+
- name: Prepare
41+
run: |
42+
platform=${{ matrix.platform }}
43+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v3
47+
48+
- name: Login to GitHub Container Registry
49+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Build and push to GitHub Container Registry
57+
id: build-ghcr
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
file: Dockerfile
62+
platforms: ${{ matrix.platform }}
63+
push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
64+
tags: |
65+
${{ env.GITHUB_REPO }}:latest
66+
${{ env.GITHUB_REPO }}:${{ github.sha }}
67+
cache-from: type=gha
68+
cache-to: type=gha,mode=max
69+
70+
- name: Export digest
71+
run: |
72+
mkdir -p ${{ runner.temp }}/digests
73+
digest="${{ steps.build-ghcr.outputs.digest }}"
74+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
75+
76+
- name: Upload digest
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: digests-${{ env.PLATFORM_PAIR }}
80+
path: ${{ runner.temp }}/digests/*
81+
if-no-files-found: error
82+
retention-days: 1
83+
84+
merge:
85+
runs-on: ubuntu-latest
86+
needs:
87+
- build
88+
steps:
89+
- name: Download digests
90+
uses: actions/download-artifact@v4
91+
with:
92+
path: ${{ runner.temp }}/digests
93+
pattern: digests-*
94+
merge-multiple: true
95+
96+
- name: Login to GitHub Container Registry
97+
uses: docker/login-action@v3
98+
with:
99+
registry: ghcr.io
100+
username: ${{ github.actor }}
101+
password: ${{ secrets.GITHUB_TOKEN }}
102+
103+
- name: Set up Docker Buildx
104+
uses: docker/setup-buildx-action@v3
105+
106+
- name: Create manifest list and push
107+
working-directory: ${{ runner.temp }}/digests
108+
run: |
109+
docker buildx imagetools create \
110+
-t ghcr.io/${{ github.repository }}:latest \
111+
-t ghcr.io/${{ github.repository }}:${{ github.sha }} \
112+
$(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
113+
114+
- name: Inspect image
115+
run: |
116+
REPO="ghcr.io/${{ github.repository }}"
117+
docker buildx imagetools inspect ${REPO}:latest
118+
docker buildx imagetools inspect ${REPO}:${{ github.sha }}

0 commit comments

Comments
 (0)