Check if changed #14
Workflow file for this run
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 | |
on: | |
schedule: | |
- cron: '42 02 * * *' | |
push: | |
branches: ["main"] | |
pull_request: | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash -leoux pipefail {0} | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
concurrency: ci-${{ github.ref }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login into registry | |
uses: docker/login-action@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
load: true | |
tags: ghcr.io/${{ github.repository }}:test | |
- name: Check if changed | |
id: checkchanged | |
run: | | |
mkdir tmp | |
cd tmp | |
docker pull --platform linux/amd64 ghcr.io/${{ github.repository }}:latest || exit 0 | |
img=$(docker create --platform linux/amd64 ghcr.io/${{ github.repository }}:latest) | |
docker export $img -o latest.tar | |
docker rm $img | |
img=$(docker create --platform linux/amd64 ghcr.io/${{ github.repository }}:test) | |
docker export $img -o test.tar | |
docker rm $img | |
mkdir test | |
mkdir latest | |
tar xf test.tar -C test | |
tar xf latest.tar -C latest | |
rm -rf {test,latest}/var/{log,cache} | |
if diff -q -r --no-dereference test latest; then | |
echo "CHECKEQUALS=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Changed | |
if: steps.checkchanged.outputs.CHECKEQUALS == 'true' | |
run: echo changed | |
- name: Changed | |
if: steps.checkchanged.outputs.CHECKEQUALSX == 'true' | |
run: echo unchanged | |
- name: Check if changed | |
id: checkchangedb | |
run: | | |
rm -rf tmp | |
mkdir tmp | |
cd tmp | |
docker pull --platform linux/amd64 ghcr.io/${{ github.repository }}:latest || exit 0 | |
img=$(docker create --platform linux/amd64 ghcr.io/${{ github.repository }}:latest) | |
docker export $img -o latest.tar | |
docker rm $img | |
img=$(docker create --platform linux/amd64 ghcr.io/${{ github.repository }}:test) | |
docker export $img -o test.tar | |
docker rm $img | |
mkdir test | |
mkdir latest | |
tar xf test.tar -C test | |
tar xf latest.tar -C latest | |
if diff -q -r --no-dereference test latest; then | |
echo "CHECKEQUALS=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Changed | |
if: steps.checkchangedb.outputs.CHECKEQUALS == 'true' | |
run: echo changed | |
- name: Changed | |
if: steps.checkchangedb.outputs.CHECKEQUALSX == 'true' | |
run: echo unchanged | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
if: github.event_name != 'pull_request' && steps.checkchanged.outputs.CHECKEQUALS == 'true' | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ghcr.io/${{ github.repository }}:latest |