Skip to content

Automated Update of Named Cache #890

Automated Update of Named Cache

Automated Update of Named Cache #890

# Name of the workflow
name: Automated Update of Named Cache
# Define the events that trigger the workflow
on:
# Trigger the workflow on a schedule (every day at midnight)
schedule:
- cron: "0 0 * * *"
# Allow manual triggering of the workflow
workflow_dispatch:
# Define the jobs in the workflow
jobs:
# Define a job named "build"
build:
# Name of the job that will be displayed on GitHub
name: Refresh Named Cache
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Environment variables available to all steps in the job
env:
NAMED_CACHE_URL: https://www.internic.net/domain/named.cache
NAMED_CACHE_PATH: assets/named.cache
# Define the steps in the job
steps:
# Check out the repository code
- name: Check out code into the Go module directory
uses: actions/checkout@v4
# Get the current SHA-3-512 hash of the file
- name: Get the current SHA-3-512 hash of file
run: echo "NAMED_CACHE_CURRENT_HASH=$(openssl dgst -sha3-512 "${{ env.NAMED_CACHE_PATH }}" | awk '{print $2}')" >> $GITHUB_ENV
# Get the future SHA-3-512 hash of the file
- name: Get the future SHA-3-512 hash of file
run: echo "NAMED_CACHE_FUTURE_HASH=$(curl --silent "${{ env.NAMED_CACHE_URL }}" | openssl dgst -sha3-512 | awk '{print $2}')" >> $GITHUB_ENV
# Check if an update is needed
- name: Verify necessity of update
run: |
if [ "${{ env.NAMED_CACHE_CURRENT_HASH }}" != "${{ env.NAMED_CACHE_FUTURE_HASH }}" ]; then
curl "${{ env.NAMED_CACHE_URL }}" -o "${{ env.NAMED_CACHE_PATH }}"
else
echo "No update needed"
exit 0
fi
# Push the updated file to GitHub
- name: Upload the refreshed named.cache to GitHub
run: |
git config user.name github-actions
git config user.email github-actions@github.com
if git diff --exit-code --quiet -- "${{ env.NAMED_CACHE_PATH }}"; then
echo "No changes to commit"
exit 0
else
git add "${{ env.NAMED_CACHE_PATH }}"
git commit -m "Updated named.cache $(date)"
git push
fi