Skip to content

Commit 45243f3

Browse files
committed
feat: Update build process
1 parent 6445d5e commit 45243f3

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

.github/workflows/push.yml

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
name: Build Artifacts
2+
permissions:
3+
contents: read
4+
packages: write
5+
actions: read
26
on:
37
release:
48
types: [created]
59
push:
610
branches:
711
- '**'
12+
paths-ignore:
13+
- 'docs/**'
14+
- 'CODE-OF-CONDUCT.md'
15+
- 'CONTRIBUTING.md'
16+
- 'LICENSE'
17+
- 'README.md'
18+
- 'SECURITY.md'
819
pull_request:
920
branches:
1021
- '**'
11-
workflow_dispatch:
12-
inputs:
13-
publish_docker:
14-
description: "Publish image to ghcr.io"
15-
type: boolean
16-
default: true
17-
required: false
18-
env:
19-
TAG_NAME: ${{ github.event.release.tag_name || github.ref }}
20-
PUSH: ${{ (github.event_name == 'workflow_dispatch' && inputs.publish_docker) || !startsWith(github.ref, 'refs/heads/dependabot') }}
21-
GITHUB_GROUP: ${{ github.repository_owner }}
22+
paths-ignore:
23+
- 'docs/**'
24+
- 'CODE-OF-CONDUCT.md'
25+
- 'CONTRIBUTING.md'
26+
- 'LICENSE'
27+
- 'README.md'
28+
- 'SECURITY.md'
29+
30+
concurrency:
31+
# On main/release, we don't want any jobs cancelled so the sha is used to name the group
32+
# On PR branches, we cancel the job if new commits are pushed
33+
# More info: https://stackoverflow.com/a/68422069/253468
34+
group: ${{ github.ref == 'refs/heads/main' && format('ci-main-{0}', github.sha) || format('ci-main-{0}', github.ref) }}
35+
cancel-in-progress: true
2236

2337
jobs:
2438
multiplatform_build:
39+
if: github.event.pull_request.user.login != 'dependabot[bot]' || github.event_name == 'pull_request'
2540
strategy:
2641
fail-fast: false
2742
matrix:
@@ -45,9 +60,19 @@ jobs:
4560
file: docker-zookeeper/docker/Dockerfile
4661
context: docker-zookeeper
4762
runs-on: ubuntu-latest
63+
name: ${{ matrix.component.name }}
4864
steps:
4965
- name: Checkout
5066
uses: actions/checkout@v4
67+
- name: Docker meta
68+
id: meta
69+
uses: docker/metadata-action@v5
70+
with:
71+
images: |
72+
ghcr.io/${{ github.repository_owner }}/${{ matrix.component.name }}
73+
tags: |
74+
type=ref,event=branch
75+
type=ref,event=tag
5176
- name: Set up QEMU
5277
uses: docker/setup-qemu-action@v3
5378
- name: Set up Docker Buildx
@@ -56,33 +81,25 @@ jobs:
5681
uses: docker/login-action@v3
5782
with:
5883
registry: ghcr.io
59-
username: ${GITHUB_ACTOR}
60-
password: ${{secrets.GITHUB_TOKEN}}
61-
- name: Prepare Tag
62-
run: echo "TAG_NAME=$(echo ${TAG_NAME} | sed 's@refs/tags/@@;s@refs/heads/@@;s@/@_@g')" >> $GITHUB_ENV
63-
- name: Prepare Group
64-
run: echo "GITHUB_GROUP=${GITHUB_GROUP,,}" >> $GITHUB_ENV
84+
username: ${{ github.actor }}
85+
password: ${{ secrets.GITHUB_TOKEN }}
6586
- name: Get package IDs for delete
6687
id: get-ids-for-delete
6788
uses: Netcracker/get-package-ids@v0.0.1
6889
with:
6990
component-name: ${{ matrix.component.name }}
70-
component-tag: ${{ env.TAG_NAME }}
71-
access-token: ${{secrets.GITHUB_TOKEN}}
72-
if: ${{ env.PUSH }}
91+
component-tag: ${{ steps.meta.outputs.tags }}
92+
access-token: ${{ secrets.GITHUB_TOKEN }}
93+
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
7394
- name: Build and push
74-
uses: docker/build-push-action@v5
95+
uses: docker/build-push-action@v6
7596
with:
7697
no-cache: true
7798
context: ${{ matrix.component.context }}
7899
file: ${{ matrix.component.file }}
79100
platforms: linux/amd64,linux/arm64
80-
push: ${{ env.PUSH }}
81-
tags: ghcr.io/${{ env.GITHUB_GROUP }}/${{ matrix.component.name }}:${{ env.TAG_NAME }}
101+
# See https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#fetching-metadata-about-a-pull-request
102+
push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
82103
provenance: false
83-
- uses: actions/delete-package-versions@v5
84-
with:
85-
package-name: ${{ matrix.component.name }}
86-
package-type: 'container'
87-
package-version-ids: ${{ steps.get-ids-for-delete.outputs.ids-for-delete }}
88-
if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }}
104+
tags: ${{ steps.meta.outputs.tags }}
105+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)