Repository navigation
126 lines (114 loc) · 4.26 KB
/
Copy pathworkflow.yml
File metadata and controls
126 lines (114 loc) · 4.26 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Release
on:
push:
branches: [ "main" ]
# Alpine may start offering a new ansible package without anything changing
# here, so check for one regularly. Nothing gets built if there is none.
schedule:
- cron: "17 4 * * 1"
workflow_dispatch:
permissions:
contents: write # to push tags
packages: write
jobs:
release:
name: Build, publish and tag
runs-on: ubuntu-latest
# A manual run from another branch must not publish `latest` or tags.
if: github.ref == 'refs/heads/main'
# Tag numbers are derived from the tags that already exist, so two runs
# must not compute them simultaneously - they would both arrive at the same
# number. Runs are queued rather than cancelled, so that every commit
# deserving a release still gets one.
concurrency:
group: release
cancel-in-progress: false
steps:
# The full history and all tags, since we compare against the previous release.
- uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
- name: Resolve the ansible version
id: ansible
run: |
version="$(bin/resolve-ansible-version.sh)"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Determine the next tag
id: tag
env:
ANSIBLE_VERSION: ${{ steps.ansible.outputs.version }}
run: |
tag="$(bin/compute-next-tag.sh "$ANSIBLE_VERSION")"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
# Pushes to main always refresh `latest`.
# Scheduled runs only build when there is something to release.
- name: Decide whether to build
id: build
env:
EVENT_NAME: ${{ github.event_name }}
TAG: ${{ steps.tag.outputs.tag }}
run: |
if [ "$EVENT_NAME" = 'schedule' ] && [ -z "$TAG" ]; then
echo 'Nothing to release'
echo 'needed=false' >> "$GITHUB_OUTPUT"
else
echo 'needed=true' >> "$GITHUB_OUTPUT"
fi
- name: Set up Docker Buildx
if: steps.build.outputs.needed == 'true'
uses: docker/setup-buildx-action@v4.4.1
# Smoke-test before publishing anything.
- name: Build for the local platform
if: steps.build.outputs.needed == 'true'
uses: docker/build-push-action@v7.4.0
with:
load: true
tags: docker-ansible:release
context: .
file: ./Dockerfile
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.version }}
- name: Smoke-test
if: steps.build.outputs.needed == 'true'
run: ./bin/smoke-test.sh docker-ansible:release
- name: Login to ghcr.io
if: steps.build.outputs.needed == 'true'
uses: docker/login-action@v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
if: steps.build.outputs.needed == 'true'
id: meta
uses: docker/metadata-action@v6.2.0
with:
images: |
ghcr.io/devture/ansible
# The first enabled tag becomes the `org.opencontainers.image.version` label.
tags: |
type=raw,value=${{ steps.tag.outputs.tag }},enable=${{ steps.tag.outputs.tag != '' }}
type=raw,value=latest
- name: Build and push
if: steps.build.outputs.needed == 'true'
uses: docker/build-push-action@v7.4.0
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: .
file: ./Dockerfile
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.version }}
# Only after the image got published, since consumers (Renovate) watch
# for new tags. Tags pushed with GITHUB_TOKEN do not trigger workflow runs.
- name: Create and push the tag
if: steps.tag.outputs.tag != ''
env:
TAG: ${{ steps.tag.outputs.tag }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag "$TAG"
git push origin "refs/tags/$TAG"