Skip to content

Commit cf3ca0c

Browse files
authored
Merge pull request #313 from sudo-bmitch/pr-gha-semver
Build conformance images with semver tags
2 parents b1257f6 + 7590719 commit cf3ca0c

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,48 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v2
16-
- name: setup go environment
17-
uses: actions/setup-go@v1
18-
with:
19-
go-version: '1.16.2'
2016
- name: Prepare
2117
id: prepare
2218
run: |
2319
VERSION=${GITHUB_REF#refs/*/}
24-
BRANCH_NAME=${GITHUB_REF#refs/heads/}
25-
if [[ "${VERSION}" == "${BRANCH_NAME}" ]]; then
26-
VERSION=$(git rev-parse --short HEAD)
20+
IMAGE=ghcr.io/${{ github.repository }}/conformance
21+
if [[ $GITHUB_REF == refs/tags/* ]]; then
22+
VERSION=${GITHUB_REF#refs/tags/}
23+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
24+
VERSION=${GITHUB_REF#refs/heads/}
25+
fi
26+
VERSION=$(echo "${VERSION}" | sed -r 's#/+#-#g')
27+
TAGS="${IMAGE}:${VERSION}"
28+
if [[ $VERSION == "${{ github.event.repository.default_branch }}" ]]; then
29+
GITSHA="$(git rev-parse --short HEAD)"
30+
TAGS="${TAGS},${IMAGE}:${GITSHA}"
31+
fi
32+
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
33+
MINOR=${VERSION%.*}
34+
MAJOR=${MINOR%.*}
35+
TAGS="${TAGS},${IMAGE}:${MINOR},${IMAGE}:${MAJOR}"
2736
fi
2837
echo ::set-output name=version::${VERSION}
29-
echo ::set-output name=ref::ghcr.io/${{ github.repository }}/conformance:${VERSION}
30-
- name: Docker Build
31-
run: |
32-
docker build \
33-
--build-arg VERSION=${{ steps.prepare.outputs.version }} \
34-
-t ${{ steps.prepare.outputs.ref }} \
35-
conformance/
38+
echo ::set-output name=tags::${TAGS}
39+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
3640
- name: Docker Login
3741
uses: docker/login-action@v1
42+
if: github.repository_owner == 'opencontainers'
3843
with:
3944
registry: ghcr.io
4045
username: ${{ secrets.GHCR_USER }}
4146
password: ${{ secrets.GHCR_TOKEN }}
42-
- name: Docker Push
43-
run: |
44-
docker push ${{ steps.prepare.outputs.ref }}
45-
- name: Clear
46-
if: always()
47-
run: |
48-
rm -f ${HOME}/.docker/config.json
47+
- name: Build and push
48+
uses: docker/build-push-action@v2
49+
with:
50+
context: conformance/
51+
# platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
52+
push: ${{ github.event_name != 'pull_request' && github.repository_owner == 'opencontainers' }}
53+
tags: ${{ steps.prepare.outputs.tags }}
54+
build-args: |
55+
VERSION=${{ steps.prepare.outputs.version }}
56+
labels: |
57+
org.opencontainers.image.created=${{ steps.prepare.outputs.created }}
58+
org.opencontainers.image.source=${{ github.repositoryUrl }}
59+
org.opencontainers.image.version=${{ steps.prepare.outputs.version }}
60+
org.opencontainers.image.revision=${{ github.sha }}

0 commit comments

Comments
 (0)