Skip to content

Commit 5f083ef

Browse files
committed
add workflow to release docker image to github package
1 parent d968819 commit 5f083ef

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: ghcr
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
env:
7+
IMAGE_NAME: template-go
8+
jobs:
9+
ghcr:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
permissions:
13+
packages: write
14+
contents: read
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: docker/login-action@v3
18+
with:
19+
registry: ghcr.io
20+
username: ${{ github.actor }}
21+
password: ${{ secrets.GITHUB_TOKEN }}
22+
- name: Set Versions
23+
uses: actions/github-script@v7
24+
id: set_version
25+
with:
26+
script: |
27+
const tag = context.ref.substring(10)
28+
const no_v = tag.replace('v', '')
29+
const dash_index = no_v.lastIndexOf('-')
30+
const no_dash = (dash_index > -1) ? no_v.substring(0, dash_index) : no_v
31+
core.setOutput('tag', tag)
32+
core.setOutput('no-v', no_v)
33+
core.setOutput('no-dash', no_dash)
34+
- name: Set meta data tag = ${{steps.set_version.outputs.no-dash}}
35+
uses: docker/metadata-action@v5
36+
id: meta
37+
with:
38+
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=semver,pattern={{version}},value=v${{steps.set_version.outputs.no-dash}}
41+
type=raw,value=latest
42+
- uses: docker/build-push-action@v5
43+
with:
44+
push: true
45+
context: .
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
[![docker](https://github.com/ks6088ts/template-go/actions/workflows/docker.yaml/badge.svg?branch=main)](https://github.com/ks6088ts/template-go/actions/workflows/docker.yaml?query=branch%3Amain)
77
[![docker-release](https://github.com/ks6088ts/template-go/actions/workflows/docker-release.yaml/badge.svg)](https://github.com/ks6088ts/template-go/actions/workflows/docker-release.yaml)
8+
[![ghcr-release](https://github.com/ks6088ts/template-go/actions/workflows/ghcr-release.yaml/badge.svg)](https://github.com/ks6088ts/template-go/actions/workflows/ghcr-release.yaml)
89

910
# template-go
1011

0 commit comments

Comments
 (0)