Skip to content

Commit 44cb128

Browse files
authored
Merge pull request #25 from jim380/jay/refine-build-publish
ci: refine build-and-publish workflow
2 parents 65a8a82 + af6089d commit 44cb128

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed
Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,87 @@
11
name: Build and Publish
22

33
on:
4-
# run it on push to the default repository branch
54
push:
6-
branches: [master, develop]
7-
# run it during pull request
8-
pull_request:
9-
# Allows you to run this workflow manually from the Actions tab
5+
branches: [master, develop, jay/*]
6+
tags:
7+
- "v[0-9]+.[0-9]+.[0-9]+"
8+
- "v[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+"
9+
- "[v]?[0-9]+.[0-9]+.[0-9]+(-rc|-alpha|-beta)?[0-9]*"
1010
workflow_dispatch:
1111

12+
permissions:
13+
contents: write
14+
repository-projects: write
15+
packages: write
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
1221
env:
1322
REGISTRY: ghcr.io
1423
IMAGE_NAME: ${{ github.repository }}
1524

1625
jobs:
17-
docker:
18-
name: Build Docker image and push to repositories
19-
# run only when code is compiling and tests are passing
26+
publish:
27+
name: Build and Publish
2028
runs-on: ubuntu-latest
2129
permissions:
22-
contents: read
30+
contents: write
2331
packages: write
2432

2533
# steps to perform in job
2634
steps:
2735
- name: Checkout code
28-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v3
2940

30-
# setup Docker buld action
3141
- name: Set up Docker Buildx
3242
id: buildx
33-
uses: docker/setup-buildx-action@v1
43+
uses: docker/setup-buildx-action@v3
3444

3545
- name: Login to Github Packages
36-
uses: docker/login-action@v1
46+
uses: docker/login-action@v3
3747
with:
3848
registry: ${{ env.REGISTRY }}
3949
username: ${{ github.actor }}
40-
password: ${{ github.token }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
4151

4252
- name: Extract metadata (tags, labels) for Docker
4353
id: meta
44-
uses: docker/metadata-action@v2
54+
uses: docker/metadata-action@v5
4555
with:
4656
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4757

58+
- name: Sanitize GitHub ref name
59+
id: sanitize
60+
run: echo "::set-output name=ref_name::$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9_.-]/-/g' | tr '[:upper:]' '[:lower:]')"
61+
62+
- name: Sanitize repository name
63+
id: sanitize_repo
64+
run: echo "::set-output name=repo_name::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')"
65+
4866
- name: Build image and push to GitHub Container Registry
49-
uses: docker/build-push-action@v4
67+
uses: docker/build-push-action@v5
5068
with:
51-
# Note: tags has to be all lower-case
52-
tags: ${{ steps.meta.outputs.tags }}
53-
# build on feature branches, push only on master
69+
labels: ${{ steps.meta.outputs.labels }}
70+
tags: |
71+
${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }}:${{ steps.sanitize.outputs.ref_name }}
72+
${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }}:latest
5473
push: true
74+
cache-from: type=gha
75+
cache-to: type=gha,mode=max
76+
outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }},name-canonical=true,push=true
5577

5678
- name: Image digest
5779
run: echo ${{ steps.docker_build.outputs.digest }}
80+
81+
- name: Create GitHub Release
82+
uses: ncipollo/release-action@v1
83+
with:
84+
allowUpdates: true
85+
generateReleaseNotes: true
86+
body: ${{ steps.changelog.outputs.clean_changelog }}
87+
artifacts: ""

0 commit comments

Comments
 (0)