Check for new dotnet image #240
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: Check for new dotnet image | |
on: | |
schedule: | |
- cron: '12 19 * * *' | |
workflow_dispatch: | |
jobs: | |
check_image_hash: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
id: checkout_repository | |
uses: actions/checkout@v4 | |
- name: Pull Docker image | |
id: pull_latest_image | |
run: docker pull mcr.microsoft.com/dotnet/runtime:8.0 | |
- name: Get current hash | |
id: get_current_hash | |
run: | | |
CURRENT_HASH=$(docker save mcr.microsoft.com/dotnet/runtime:8.0 | tar -xO | shasum -a 256 | cut -d' ' -f1) | |
echo "CURRENT_HASH=$CURRENT_HASH" >> $GITHUB_ENV | |
- name: Get previous hash | |
id: get_previous_hash | |
run: | | |
PREVIOUS_HASH=$(cat upstream-releases/dotnet_hash.txt) | |
echo "PREVIOUS_HASH=$PREVIOUS_HASH" >> $GITHUB_ENV | |
- name: Compare hashes | |
id: compare_hashes | |
run: | | |
if [ -n "${{ env.PREVIOUS_HASH }}" ]; then | |
if [ "${{ env.PREVIOUS_HASH }}" = "${{ env.CURRENT_HASH }}" ]; then | |
echo "Hashes match. No change detected." | |
echo "MODIFIED=false" >> $GITHUB_ENV | |
else | |
echo "Hashes differ. There's a change in the image." | |
echo "${{ env.CURRENT_HASH }}" > upstream-releases/dotnet_hash.txt | |
# Trigger the build-and-push workflow | |
curl -X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token ${{ secrets.PAT }}" \ | |
https://api.github.com/repos/hucknz/cumulusmx/actions/workflows/v4-container-build-push.yml/dispatches \ | |
-d '{"ref":"main"}' | |
echo "MODIFIED=true" >> $GITHUB_ENV | |
fi | |
else | |
echo "Previous hash not found. This is likely the first run." | |
echo "${{ env.CURRENT_HASH }}" > upstream-releases/dotnet_hash.txt | |
fi | |
- name: Commit latest hash | |
id: commit_latest_hash | |
if: env.MODIFIED == 'true' | |
run: | | |
git config --global user.name 'hucknz' | |
git config --global user.email '[email protected]' | |
git commit -am "New dotnet hash found" | |
git push | |
- name: Notify new image found | |
id: notify_new_image | |
if: env.MODIFIED == 'true' | |
uses: sarisia/actions-status-discord@v1 | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
noprefix: true | |
status: ${{ job.status }} | |
title: ${{ github.workflow}} ${{ job.status }} | |
description: "A new dotnet base image was found. The build and push workflow has been triggered." | |
- name: Notify failure | |
if: failure() | |
uses: sarisia/actions-status-discord@v1 | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
noprefix: true | |
status: ${{ job.status }} | |
title: "dotnet base image check ${{ job.status }}" |