Skip to content

Check External Repo for Updates #5

Check External Repo for Updates

Check External Repo for Updates #5

name: Check External Repo for Updates
on:
schedule:
- cron: '0 12 2 * *' # Runs Tues at 12:00 UTC
workflow_dispatch: # Allows manual triggering
jobs:
check-updates:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the current repository
- name: Checkout Repository
uses: actions/checkout@v4
# Step 2: Restore the last known commit hash from the cache
- name: Restore Last Known Commit Hash
id: restore_cache
uses: actions/cache/restore@v4
with:
path: .last_known_commit
key: ${{ runner.os }}-last-known-commit
# Step 3: Fetch the latest commit hash from the external repository
- name: Get Latest Commit from External Repo
id: get_latest_commit
run: |
# Replace with the external repo URL and branch/tag
EXTERNAL_REPO="https://github.com/pantheon-upstreams/drupal-composer-managed.git"
BRANCH="main"
# Fetch the latest commit hash
LATEST_COMMIT=$(git ls-remote $EXTERNAL_REPO refs/heads/$BRANCH | awk '{print $1}')
echo "Latest commit: $LATEST_COMMIT"
# Output the commit hash
echo "LATEST_COMMIT=$LATEST_COMMIT" >> $GITHUB_ENV
# Step 4: Compare with the stored commit hash
- name: Check for Updates
id: check_updates
run: |
# Check if the cache restored the file
if [ -f ".last_known_commit" ]; then
LAST_COMMIT=$(cat .last_known_commit)
else
LAST_COMMIT=""
fi
echo "Last known commit: $LAST_COMMIT"
echo "Latest commit: $LATEST_COMMIT"
# Compare hashes
if [ "$LATEST_COMMIT" != "$LAST_COMMIT" ]; then
echo "Updates found."
echo "UPDATE_FOUND=true" >> $GITHUB_ENV
else
echo "No updates found."
echo "UPDATE_FOUND=false" >> $GITHUB_ENV
fi
# Step 5: Send an email if updates are found
- name: Send Email Notification
# if: env.UPDATE_FOUND == 'true'
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.APP_PASSWORD }}
subject: "External Repo Updated"
to: bc-bot@bluecadet.com,pinge@bluecadet.com
from: bc-bot+actor@bluecadet.com
body: |
The external repository has been updated.
Latest commit hash: ${{ env.LATEST_COMMIT }}
# Step 6: Save the latest commit hash to the cache
- name: Save Latest Commit Hash
if: env.UPDATE_FOUND == 'true'
run: echo $LATEST_COMMIT > .last_known_commit
- name: Cache Latest Commit Hash
uses: actions/cache/save@v4
with:
path: .last_known_commit
key: ${{ steps.restore_cache.outputs.cache-primary-key }}