Skip to content

Commit 72b9dcd

Browse files
authored
ci: refactor docker release workflow and image metadata (bnb-chain#12)
* ci: refactor docker release workflow and image metadata * remove duplicate * triggered by all tags
1 parent 0b3e557 commit 72b9dcd

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

.github/workflows/docker-release.yml

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: DockerImage build and push
22

33
on:
4+
workflow_dispatch:
45
push:
5-
# Publish `v1.2.3` tags as releases.
6-
tags:
7-
- v*
6+
branches:
7+
- develop
8+
- main
9+
tags: '*'
810

911
jobs:
1012
# Push image to GitHub Packages.
1113
push-op-geth:
1214
runs-on: ubuntu-latest
13-
if: github.event_name == 'push'
1415

1516
steps:
1617
- uses: actions/checkout@v3
@@ -22,28 +23,22 @@ jobs:
2223
registry: ghcr.io
2324
username: ${{ github.repository_owner }}
2425
password: ${{ secrets.GITHUB_TOKEN }}
25-
- name: ImageId
26-
id: image
27-
run: |
28-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/op-geth
29-
30-
# Change all uppercase to lowercase
31-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
32-
# Strip git ref prefix from version
33-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
34-
# Strip "v" prefix from tag name
35-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
36-
# Use Docker `latest` tag convention
37-
[ "$VERSION" == "main" ] && VERSION=latest
38-
echo "IMAGE_ID=$IMAGE_ID">>$GITHUB_OUTPUT
39-
echo "VERSION=$VERSION">>$GITHUB_OUTPUT
26+
- name: image meta
27+
id: meta
28+
uses: docker/metadata-action@v5
29+
with:
30+
images: |
31+
ghcr.io/${{ github.repository_owner }}/op-geth
32+
tags: |
33+
type=ref,event=branch
34+
type=ref,event=tag
35+
type=semver,pattern={{version}}
36+
type=sha
4037
- name: Build and push
4138
uses: docker/build-push-action@v4
4239
with:
4340
context: .
4441
file: ./Dockerfile
4542
push: true
46-
tags: ${{ steps.image.outputs.IMAGE_ID }}:${{ steps.image.outputs.VERSION }},${{ steps.image.outputs.IMAGE_ID }}:latest
47-
cache-from: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache
48-
cache-to: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache,mode=max
49-
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)