Check for metadata changes #795
This file contains hidden or 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
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "30 10,14,19 * * *" | |
| name: Check for metadata changes | |
| jobs: | |
| check_data: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| COMMIT_CHANGES: ${{ steps.rscript.outputs.COMMIT_CHANGES}} | |
| POST_BSKY: ${{ steps.rscript.outputs.POST_BSKY}} | |
| POST_TEXT: ${{ steps.rscript.outputs.POST_TEXT}} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| # Install R and dependencies | |
| - uses: r-lib/actions/setup-r@v2 | |
| - uses: r-lib/actions/setup-r-dependencies@v2 | |
| with: | |
| packages: | | |
| censusapi | |
| # Run R script to grab metadata and compare against saved .csv | |
| - name: Run update-metadata.R | |
| id: rscript | |
| run: | | |
| Rscript scripts/update-metadata.R | |
| - name: List key vars | |
| run: | | |
| echo "Did endpoints.csv change: ${{env.UPDATED_DATA}}" | |
| echo "Should changes be committed: ${{env.COMMIT_CHANGES}}" | |
| echo "Should it post on bsky (if changes are committed): ${{env.POST_BSKY}}" | |
| echo "What should the post text be: ${{env.POST_TEXT}}" | |
| # Commit using message text prepared in R | |
| # If anyone is adapting this code make sure to change the user.name and user.email to your own! | |
| - name: Commit changes | |
| if: ${{ env.COMMIT_CHANGES == 'true' }} | |
| run: | | |
| # Configure git user | |
| git config user.name "hrecht[bot]" | |
| git config user.email "9753760+hrecht[bot]@users.noreply.github.com" | |
| # Commit files | |
| git add . | |
| git commit -m "${{env.COMMIT_MESSAGE}}" || exit 0 | |
| git push | |
| # Pause a little before deploying to github pages | |
| # Otherwise it's happening too quickly to work | |
| - name: Build pause | |
| if: ${{ env.COMMIT_CHANGES == 'true' }} | |
| run: | | |
| echo "Pause before building site" | |
| sleep 45 | |
| # Build the page only if changes were committed | |
| build_site: | |
| needs: check_data | |
| if: ${{ needs.check_data.outputs.COMMIT_CHANGES == 'true' }} | |
| uses: ./.github/workflows/deploy-site.yml | |
| secrets: inherit | |
| # Post to Bluesky based on R output, after site built | |
| post_bluesky: | |
| runs-on: ubuntu-latest | |
| needs: [check_data, build_site] | |
| if: ${{ needs.check_data.outputs.POST_BSKY == 'true' && needs.check_data.outputs.COMMIT_CHANGES == 'true' }} | |
| steps: | |
| - name: Set up end of post text | |
| run: | | |
| echo | |
| POST_END=$(cat << EOF | |
| See the full tracker: https://www.hrecht.com/census-api-datasets/ | |
| EOF | |
| ) | |
| echo "POST_END<<EOF" >> $GITHUB_ENV | |
| echo "$POST_END" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| # Pause a little before posting to give time for page to build | |
| - name: Bluesky pause | |
| run: | | |
| echo "Pause before posting to Bluesky" | |
| echo "Post text: ${{needs.check_data.outputs.POST_TEXT}}" | |
| sleep 30 | |
| - name: Send post | |
| uses: myConsciousness/bluesky-post@v5 | |
| with: | |
| text: ${{ needs.check_data.outputs.POST_TEXT }} ${{ env.POST_END }} | |
| link-preview-url: "https://www.hrecht.com/census-api-datasets/" | |
| identifier: ${{ secrets.BLUESKY_IDENTIFIER }} | |
| password: ${{ secrets.BLUESKY_PASSWORD }} | |