Merge pull request #4 from truenas/rebuild-rsync #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |