-
Notifications
You must be signed in to change notification settings - Fork 1
133 lines (120 loc) · 4.49 KB
/
ci.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
- cron: '0 0 * * 0'
env:
IMAGE_NAME: haxorof/ansible-lint
LATEST_OS: alpine
LATEST_VERSION: v24
jobs:
build_push:
runs-on: ubuntu-latest
strategy:
matrix:
os: [alpine, almalinux]
version: [v6, v24]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
id: prep
run: |
cp requirements/${MATRIX_VERSION}/requirements.txt requirements/requirements.txt
TAGS="${IMAGE_NAME}:${MATRIX_VERSION}-${MATRIX_OS}"
TEST_TAG="${TAGS}"
if [[ "$MATRIX_OS" == "$LATEST_OS" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:$MATRIX_VERSION"
if [[ "$MATRIX_VERSION" == "$LATEST_VERSION" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:latest-${MATRIX_OS},${IMAGE_NAME}:latest"
fi
elif [[ "$MATRIX_VERSION" == "$LATEST_VERSION" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:latest-${MATRIX_OS}"
fi
echo "test_tag=${TEST_TAG}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
env:
MATRIX_OS: ${{ matrix.os }}
MATRIX_VERSION: ${{ matrix.version }}
- name: Lint Dockerfile
uses: docker://replicated/dockerfilelint:latest
with:
args: Dockerfile.${{ matrix.os }}
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Build (test build linux/amd64)
uses: docker/[email protected]
with:
load: true
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ matrix.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
tags: ${{ steps.prep.outputs.test_tag }}
context: .
file: ./Dockerfile.${{ matrix.os }}
- name: Test built image
run: |
docker run --rm -v ${PWD}/test/${{ matrix.version }}:/mnt:ro ${{ steps.prep.outputs.test_tag }} -vv --force-color .
- name: Login to DockerHub
uses: docker/[email protected]
if: ${{ endsWith(github.ref, '/master') }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push (linux/amd64,linux/arm64)
uses: docker/[email protected]
with:
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ matrix.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
tags: ${{ steps.prep.outputs.tags }}
context: .
file: ./Dockerfile.${{ matrix.os }}
platforms: linux/amd64,linux/arm64
push: ${{ endsWith(github.ref, '/master') }}
dependabot:
if: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }}
needs: build_push
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
if: ${{steps.dependabot-metadata.outputs.package-ecosystem == 'github_actions'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
update_docker_hub_description:
if: ${{ endsWith(github.ref, '/master') }}
needs: build_push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.IMAGE_NAME }}