Skip to content

Commit d0a7936

Browse files
authored
Merge pull request #725 from viperproject/package-description
2 parents 5a943b0 + e46c19e commit d0a7936

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

.github/workflows/test.yml

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ jobs:
1515
build-test-deploy-container:
1616
runs-on: ubuntu-latest
1717
env:
18-
IMAGE_NAME: gobra
18+
IMAGE_ID: ghcr.io/${{ github.repository_owner }}/gobra
19+
# image labels are new-line separated key value pairs (according to https://specs.opencontainers.org/image-spec/annotations/):
20+
IMAGE_LABELS: |
21+
org.opencontainers.image.authors=Viper Project <https://viper.ethz.ch>
22+
org.opencontainers.image.url=https://github.com/viperproject/gobra/pkgs/container/gobra
23+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
24+
org.opencontainers.image.revision=${{ github.sha }}
25+
org.opencontainers.image.licenses=MPL-2.0
26+
org.opencontainers.image.description=Gobra image for revision ${{ github.sha }} built by workflow run ${{ github.run_id }}
1927
CONCLUSION_SUCCESS: "success"
2028
CONCLUSION_FAILURE: "failure"
2129
# Output levels according to severity.
@@ -33,35 +41,51 @@ jobs:
3341
SILICON_SILVER_REF=$(git -C viperserver/silicon/silver rev-parse HEAD) && \
3442
CARBON_SILVER_REF=$(git -C viperserver/carbon/silver rev-parse HEAD) && \
3543
if [ "$SILICON_SILVER_REF" != "$CARBON_SILVER_REF" ]; then echo "Silicon and Carbon reference different Silver commits ($SILICON_SILVER_REF and $CARBON_SILVER_REF)" && exit 1 ; fi
36-
- name: Create image tag
37-
run: |
38-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
39-
40-
# Change all uppercase to lowercase
41-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
42-
# Strip git ref prefix from version
43-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
44-
# Strip "v" prefix from tag name
45-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v\.?//')
46-
# Use Docker `latest` tag convention
47-
[ "$VERSION" == "master" ] && VERSION=latest
48-
echo "IMAGE_TAG=$IMAGE_ID:$VERSION" >> $GITHUB_ENV
4944
5045
# used to enable Docker caching (see https://github.com/docker/build-push-action)
5146
- name: Set up Docker Buildx
5247
uses: docker/setup-buildx-action@v3
5348

49+
- name: Create image creation label
50+
run: |
51+
CREATED_LABEL="org.opencontainers.image.created=$(date --rfc-3339=seconds)"
52+
echo "CREATED_LABEL=$CREATED_LABEL" >> $GITHUB_ENV
53+
54+
- name: Create image metadata
55+
id: image-metadata
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ${{ env.IMAGE_ID }}
59+
labels: |
60+
${{ env.IMAGE_LABELS }}
61+
${{ env.CREATED_LABEL }}
62+
tags: |
63+
# the first 4 tags correspond to the default options
64+
type=schedule
65+
type=ref,event=branch
66+
type=ref,event=tag
67+
type=ref,event=pr
68+
# use (short) commit hash as tag:
69+
type=sha
70+
# use latest tag for default branch and with highest priority (1000 is the highest default priority for the other types):
71+
type=raw,value=latest,priority=1100,enable={{is_default_branch}}
72+
73+
- name: Get first tag
74+
run: echo "IMAGE_TAG=$(echo "${{ steps.image-metadata.outputs.tags }}" | head -1)" >> $GITHUB_ENV
75+
5476
- name: Build image up to including stage 'build'
77+
id: image-build
5578
# note that the action's name is misleading: this step does NOT push
5679
uses: docker/build-push-action@v5
5780
with:
5881
context: .
5982
load: true # make the built image available in docker (locally)
6083
target: build # only build up to and including stage 'build'
6184
file: workflow-container/Dockerfile
62-
tags: ${{ env.IMAGE_TAG }}
63-
labels: "runnumber=${{ github.run_id }}"
85+
tags: ${{ steps.image-metadata.outputs.tags }}
86+
labels: ${{ steps.image-metadata.outputs.labels }}
6487
push: false
88+
provenance: false # without this, GH displays 2 architecture (unknown/unknown) and omits labels
6589
# use GitHub cache:
6690
cache-from: type=gha, scope=${{ github.workflow }}
6791
cache-to: type=gha, scope=${{ github.workflow }}
@@ -172,9 +196,10 @@ jobs:
172196
context: .
173197
load: true # make the built image available in docker (locally)
174198
file: workflow-container/Dockerfile
175-
tags: ${{ env.IMAGE_TAG }}
176-
labels: "runnumber=${{ github.run_id }}"
199+
tags: ${{ steps.image-metadata.outputs.tags }}
200+
labels: ${{ steps.image-metadata.outputs.labels }}
177201
push: false
202+
provenance: false # without this, GH displays 2 architecture (unknown/unknown) and omits labels
178203
# use GitHub cache:
179204
cache-from: type=gha, scope=${{ github.workflow }}
180205
cache-to: type=gha, scope=${{ github.workflow }}
@@ -215,9 +240,10 @@ jobs:
215240
with:
216241
context: .
217242
file: workflow-container/Dockerfile
218-
tags: ${{ env.IMAGE_TAG }}
219-
labels: "runnumber=${{ github.run_id }}"
243+
tags: ${{ steps.image-metadata.outputs.tags }}
244+
labels: ${{ steps.image-metadata.outputs.labels }}
220245
push: true
246+
provenance: false # without this, GH displays 2 architecture (unknown/unknown) and omits labels
221247
# use GitHub cache:
222248
cache-from: type=gha, scope=${{ github.workflow }}
223249
cache-to: type=gha, scope=${{ github.workflow }}

0 commit comments

Comments
 (0)