Skip to content

Instantly share code, notes, and snippets.

@potibm
Last active March 29, 2024 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potibm/e0dacccbacd0293c021d84d2cbce2adc to your computer and use it in GitHub Desktop.
Save potibm/e0dacccbacd0293c021d84d2cbce2adc to your computer and use it in GitHub Desktop.
GitHub Action to submit changed Urls to IndexNow
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Build Jekyll site
- name: Generate CSV with MD5 Hashes
run: |
cd build
find . -type f -exec md5sum {} + | sed 's/\.\///' | sort -t $'\t' -k 2 > file_hashes.csv
working-directory: ${{ github.workspace }}
- name: Upload artifacts
deploy:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Fetch file_hashes.csv from S3
id: fetch_file_hashes
run: |
aws s3 cp s3://${{ inputs.s3-bucket }}/file_hashes.csv prev_file_hashes.csv || touch prev_file_hashes.csv
echo "content<<EOF" >> "$GITHUB_OUTPUT"
cat prev_file_hashes.csv >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
rm prev_file_hashes.csv
- name: Sync to S3
- name: Determine changed files
id: changed_files
run: |
echo "changed_files<<EOF" >> "$GITHUB_OUTPUT"
diff <(echo "$S3_FILE_HASHES") file_hashes.csv | grep -E "^[<>]" | sed -E 's/^[<>] [0-9a-f]+[[:space:]]*//' | sort | uniq >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
env:
S3_FILE_HASHES: ${{ steps.fetch_file_hashes.outputs.content }}
- name: Call IndexNow API for changed file
if: inputs.indexnow-api-key && inputs.hostname
run: |
for FILE in $CHANGED_FILES; do
URL="https://${{ inputs.hostname }}/$FILE"
REQUEST_URL="https://api.indexnow.org/indexnow?url=$URL&key=${{ inputs.indexnow-api-key }}"
echo "Calling IndexNow API for file: $URL"
curl -sS "$REQUEST_URL"
done
shell: bash
env:
CHANGED_FILES: ${{ steps.changed_files.outputs.changed_files }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment