adp #33821
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: adp | |
on: | |
schedule: | |
- cron: '*/20 * * * *' | |
workflow_dispatch: | |
jobs: | |
process-reference-files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: check_out_contrib1_repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
repository: 'ElectricNroff/test2' | |
path: 'data-contrib1' | |
- name: process_new_files_from_contrib1 | |
env: | |
G_READ_API_KEY: ${{ secrets.G_READ_API_KEY }} | |
G_WRITE_API_KEY: ${{ secrets.G_WRITE_API_KEY }} | |
run: | | |
CONTRIBUTOR="contrib1" | |
DIR_IN_PRIMARY_REPO="ElectricNroff/test2" | |
CHECKOUT_PATH="data-$CONTRIBUTOR" | |
DIRECTORY="references" | |
cd $CHECKOUT_PATH | |
curl -s -S -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://raw.githubusercontent.com/ElectricNroff/data/main/actions-bin/create-file-via-api.py > create-file-via-api.py | |
curl -s -S -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://raw.githubusercontent.com/ElectricNroff/data/main/actions-bin/read-file-via-api.py > read-file-via-api.py | |
CURRENT_SHA=$(git rev-parse HEAD) | |
PREVIOUS_SHA=$(python read-file-via-api.py $DIR_IN_PRIMARY_REPO last_run_sha) | |
if [ -n "$PREVIOUS_SHA" ]; then | |
git diff --name-only --diff-filter=A $PREVIOUS_SHA $CURRENT_SHA $DIRECTORY | while read REFERENCE_FILE; do | |
echo "Processing: $REFERENCE_FILE" | |
python create-file-via-api.py $REFERENCE_FILE $CONTRIBUTOR | |
done | |
fi | |
- name: check_out_primary_repository | |
uses: actions/checkout@v3 | |
with: | |
ref: 'main' | |
fetch-depth: 0 | |
repository: 'ElectricNroff/data' | |
path: 'data-primary' | |
- name: process_new_files_from_primary | |
env: | |
A_API_KEY: ${{ secrets.A_API_KEY }} | |
run: | | |
DIR_IN_PRIMARY_REPO="ElectricNroff/data" | |
CHECKOUT_PATH="data-primary" | |
DIRECTORY="references" | |
PRIMARY_LAST_RUN_SHA="last_run_shas/$DIR_IN_PRIMARY_REPO/last_run_sha" | |
cd $CHECKOUT_PATH | |
CURRENT_SHA=$(git rev-parse HEAD) | |
PREVIOUS_SHA=$(cat $PRIMARY_LAST_RUN_SHA) | |
if [ -n "$PREVIOUS_SHA" ]; then | |
git diff --name-only --diff-filter=A $PREVIOUS_SHA $CURRENT_SHA $DIRECTORY | while read REFERENCE_FILE; do | |
echo "Processing: $REFERENCE_FILE" | |
python actions-bin/adp.py $CHECKOUT_PATH $DIRECTORY $REFERENCE_FILE | |
done | |
fi | |
echo $CURRENT_SHA > $PRIMARY_LAST_RUN_SHA | |
git config user.name "GitHub Action" | |
git config user.email "action@github.example.com" | |
git add $PRIMARY_LAST_RUN_SHA | |
THIS_CONTRIBUTOR="contrib1" | |
THIS_CONTRIBUTOR_REPO="ElectricNroff/test2" | |
CURRENT_SHA_OF_CONTRIBUTOR=$(cd ../data-$THIS_CONTRIBUTOR; git rev-parse HEAD) | |
CONTRIBUTOR_LAST_RUN_SHA="last_run_shas/$THIS_CONTRIBUTOR_REPO/last_run_sha" | |
echo $CURRENT_SHA_OF_CONTRIBUTOR > $CONTRIBUTOR_LAST_RUN_SHA | |
git add $CONTRIBUTOR_LAST_RUN_SHA | |
if [ -s .rbp ]; then | |
RBP_BASENAME=$(head -1 .rbp) | |
RBP_PATHNAME=rbp/$RBP_BASENAME | |
git add $RBP_PATHNAME | |
fi | |
git commit -m "Update last run SHA for primary" | |
git push |