-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (89 loc) · 3.17 KB
/
publish.yaml
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
name: Publish Docker image
on:
workflow_dispatch:
push:
branches:
- master
paths:
- apps/**
pull_request:
paths:
- apps/**
env:
REPOSITORY: ixsystems
jobs:
build:
permissions:
packages: write
contents: read
name: Build
runs-on: ubuntu-22.04
strategy:
matrix:
containers:
- app: tftpd-hpa
- app: rsyncd
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v36
with:
files: |
apps/${{ matrix.containers.app }}/**
# TODO: We should later look into getting the changed files before the matrix
# and generate a matrix based on the changed files.
- name: Detect changes
id: detect_changes
shell: bash
run: |
if [ -n "${{ steps.changed-files.outputs.all_changed_files }}" ]; then
echo "Changes detected, proceeding with build."
echo "skip=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "No changes detected, skipping build."
echo "skip=true" >> $GITHUB_OUTPUT
# Login first so we can pull the manifest
# even if the repository is private
- name: Login to DockerHub
if: steps.detect_changes.outputs.skip == 'false'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Prepare
if: steps.detect_changes.outputs.skip == 'false'
id: prepare
shell: bash
run: |
# Grab the version from the VERSION file
VERSION=$(cat ./apps/${{ matrix.containers.app }}/VERSION )
result=$(docker manifest inspect "${{ env.REPOSITORY }}/${{ matrix.containers.app }}:$VERSION" || echo 1)
# Result contains 1 if the tag does not exist or a JSON object if it does.
# If the result is not 1, means the "production" tag exists.
# We should fail the build and ask for a version bump.
if [[ "$result" != 1 ]]; then
echo "Version $VERSION already exists, please bump the version in the VERSION file."
exit 1
fi
echo "Version $VERSION does not exist, proceeding with build."
# Initialize the output
OUTPUT_VERSION="$VERSION"
# If this is a pull request, append the PR number
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
OUTPUT_VERSION="unstable"
fi
# Set the output
echo "APP_VERSION=$OUTPUT_VERSION" >> $GITHUB_OUTPUT
- name: Build and push Docker images
if: ${{ steps.detect_changes.outputs.skip == 'false' && steps.prepare.outputs.APP_VERSION != '' }}
uses: docker/build-push-action@91df6b874e498451163feb47610c87c4a218c1ee
with:
context: apps/${{ matrix.containers.app }}/
push: true
tags: |
${{ env.REPOSITORY }}/${{ matrix.containers.app }}:${{ steps.prepare.outputs.APP_VERSION }}