1
- name : Docker-Publish
1
+ name : Container
2
2
3
3
on :
4
4
push :
5
- # Publish semver tags as releases.
6
- tags : [ 'v*.*.*' ]
7
-
8
- env :
9
- # Use docker.io for Docker Hub if empty
10
- REGISTRY : ghcr.io
11
- # github.repository as <account>/<repo>
12
- IMAGE_NAME : ${{ github.repository }}
13
-
5
+ branches :
6
+ - ' main '
7
+ tags :
8
+ - ' v* '
9
+ workflow_run :
10
+ workflows : [ Releaser ]
11
+ types :
12
+ - completed
13
+ pull_request :
14
14
15
15
jobs :
16
- build :
17
-
16
+ prepare-checkout :
17
+ if : github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
18
+ name : Prepare ref
19
+ runs-on : ubuntu-latest
20
+ outputs :
21
+ ref : ${{ github.event_name != 'workflow_run' && github.ref || steps.releaser.outputs.version }}
22
+ steps :
23
+ - name : Get Ref from releaser
24
+ id : releaser
25
+ if : github.event_name == 'workflow_run'
26
+ uses :
pl-strflt/uci/.github/actions/[email protected]
27
+ with :
28
+ artifacts-url : ${{ github.event.workflow_run.artifacts_url }}
29
+ publish :
30
+ name : Publish
31
+ needs : [ prepare-checkout ]
18
32
runs-on : ubuntu-latest
19
33
permissions :
20
34
contents : read
21
35
packages : write
22
- # This is used to complete the identity challenge
23
- # with sigstore/fulcio when running outside of PRs.
24
- id-token : write
25
-
26
36
steps :
27
- - name : Checkout repository
28
- uses : actions/checkout@v4
29
-
30
- # Install the cosign tool except on PR
31
- # https://github.com/sigstore/cosign-installer
32
- - name : Install cosign
33
- if : github.event_name != 'pull_request'
34
- uses : sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19
37
+ - name : Checkout
38
+ uses : actions/checkout@v3
35
39
with :
36
- cosign-release : ' v1.9.0'
37
-
38
-
39
- # Workaround: https://github.com/docker/build-push-action/issues/461
40
- - name : Setup Docker buildx
41
- uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
42
-
43
- # Login against a Docker registry except on PR
44
- # https://github.com/docker/login-action
45
- - name : Log into registry ${{ env.REGISTRY }}
46
- if : github.event_name != 'pull_request'
47
- uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
40
+ ref : ${{ needs.prepare-checkout.outputs.ref }}
41
+ - name : Set up Docker Buildx
42
+ uses : docker/setup-buildx-action@v2
43
+ - name : Log in to the Container registry
44
+ uses : docker/login-action@v2
48
45
with :
49
- registry : ${{ env.REGISTRY }}
46
+ registry : ghcr.io
50
47
username : ${{ github.actor }}
51
- password : ${{ secrets.GITHUB_TOKEN }}
52
-
53
- # Extract metadata (tags, labels) for Docker
54
- # https://github.com/docker/metadata-action
55
- - name : Extract Docker metadata
48
+ password : ${{ github.token }}
49
+ - name : Extract metadata
56
50
id : meta
57
- uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934
51
+ uses : docker/metadata-action@v4
58
52
with :
59
- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60
-
61
- # Build and push Docker image with Buildx (don't push on PR)
62
- # https://github.com/docker/build-push-action
53
+ images : ghcr.io/${{ github.repository }}
54
+ tags : |
55
+ type=semver,pattern={{raw}}
56
+ type=ref,event=branch
57
+ type=raw,value=${{ needs.prepare-checkout.outputs.ref }}
63
58
- name : Build and push Docker image
64
- id : build-and-push
65
- uses : docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
59
+ uses : docker/build-push-action@v4
66
60
with :
67
61
context : .
62
+ cache-from : type=gha
63
+ cache-to : type=gha,mode=max
68
64
push : ${{ github.event_name != 'pull_request' }}
69
65
tags : ${{ steps.meta.outputs.tags }}
70
- labels : ${{ steps.meta.outputs.labels }}
71
-
72
- # Sign the resulting Docker image digest except on PRs.
73
- # This will only write to the public Rekor transparency log when the Docker
74
- # repository is public to avoid leaking data. If you would like to publish
75
- # transparency data even for private images, pass --force to cosign below.
76
- # https://github.com/sigstore/cosign
77
- - name : Sign the published Docker image
78
- if : ${{ github.event_name != 'pull_request' }}
79
- env :
80
- COSIGN_EXPERIMENTAL : " true"
81
- # This step uses the identity token to provision an ephemeral certificate
82
- # against the sigstore community Fulcio instance.
83
- run : echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
66
+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments