-
Notifications
You must be signed in to change notification settings - Fork 21
107 lines (104 loc) · 3.94 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Release
on:
workflow_dispatch:
inputs:
override:
type: boolean
description: Replace existing tag/version
default: false
latest:
type: boolean
description: Update `:latest` on Docker Hub
default: false
jobs:
sanity_check:
runs-on: ubuntu-22.04
name: Prepare version
outputs:
tag: ${{ steps.extract.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
# get all tags
fetch-depth: 0
- name: Extract tag from Dockerfile
shell: bash
id: extract
run: |
echo tag="$(sed -rn 's/^ARG APK_VERSION=\"([0-9]+\.[0-9]+\.[0-9]+).*\"$/\1/p' Dockerfile)" >> "$GITHUB_OUTPUT"\
- name: Verify tag extraction
shell: bash
run: |
[[ -z "${{ steps.extract.outputs.tag }}" ]] && echo "Could not extract current version" && exit 1 || exit 0
- name: Check if tag exists
shell: bash
if: ${{ ! inputs.override }}
env:
TAG_URL: "https://hub.docker.com/v2/repositories/jbergstroem/mariadb-alpine/tags?page_size=100"
run: |
[[ $(git tag -l "${{ steps.extract.outputs.tag }}") || $(curl -L -s "${{ env.TAG_URL }}" | jq -r '.results[] | select(.name=="${{ steps.extract.outputs.tag }}")') ]] && \
echo "Tag already exists. Quitting." && exit 1 || exit 0
test:
name: Run e2e tests
needs:
- sanity_check
uses: ./.github/workflows/test.yml
release:
name: Build and push multi-platform
runs-on: ubuntu-22.04
needs:
- sanity_check
- test
env:
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/s390x,linux/ppc64le
image: jbergstroem/mariadb-alpine
ref_url: ${{ github.api_url }}/repos/${{ github.repository }}/git/refs
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/[email protected]
with:
platforms: ${{ env.platforms }}
- name: Enable latest tag
if: ${{ inputs.latest }}
run: echo LATEST=",${{ env.image }}:latest" >> "$GITHUB_ENV"
- name: Set build args
run: |
echo BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV"
echo BUILD_REF="$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
- name: Build containers for all platforms
uses: docker/[email protected]
with:
platforms: ${{ env.platforms }}
tags: ${{ env.image }}:${{ needs.sanity_check.outputs.tag }}${{ env.LATEST }}
push: false
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_REF=${{ env.BUILD_REF }}
BUILD_VERSION=${{ needs.sanity_check.outputs.tag }}
- name: Remove old git reference
if: ${{ inputs.override }}
run: |
curl -s -X DELETE "${{ env.ref_url }}/tags/${{ needs.sanity_check.outputs.tag }}" \
-H "Authorization: token ${{ github.token }}"
- name: Create git reference
run: |
curl -s -X POST "${{ env.ref_url }}" \
-H "Authorization: token ${{ github.token }}" \
-d '{ "ref": "refs/tags/${{ needs.sanity_check.outputs.tag }}", "sha": "${{ github.sha }}" }' | \
grep "Reference already exists" && echo "Tag already exists. Quitting." && exit 1 || exit 0
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker hub
uses: docker/[email protected]
with:
platforms: ${{ env.platforms }}
tags: ${{ env.image }}:${{ needs.sanity_check.outputs.tag }}${{ env.LATEST }}
push: true
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_REF=${{ env.BUILD_REF }}
BUILD_VERSION=${{ needs.sanity_check.outputs.tag }}