Check for metadata changes #138
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 11,20 * * *" | |
| name: Check for metadata changes | |
| jobs: | |
| check_data: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| COMMIT_CHANGES: ${{ steps.passvars.outputs.COMMIT_CHANGES}} | |
| POST_BSKY: ${{ steps.passvars.outputs.POST_BSKY}} | |
| POST_TEXT: ${{ steps.passvars.outputs.POST_TEXT}} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # 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 | |
| run: | | |
| Rscript scripts/update-metadata.R | |
| - name: Pass vars to output for use in following jobs | |
| id: passvars | |
| run: | | |
| echo "endpoints.csv changed: ${{env.UPDATED_DATA}}" | |
| echo "Should changes be committed: ${{env.COMMIT_CHANGES}}" | |
| echo "Should it post on bsky: ${{env.POST_BSKY}}" | |
| echo "COMMIT_CHANGES=${{env.COMMIT_CHANGES}}" >> $GITHUB_OUTPUT | |
| echo "POST_BSKY=${{env.POST_BSKY}}" >> $GITHUB_OUTPUT | |
| echo "POST_TEXT=${{env.POST_TEXT}}" >> $GITHUB_OUTPUT | |
| # Commit using message text prepared in R | |
| - 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 | |
| post_bluesky: | |
| runs-on: ubuntu-latest | |
| needs: check_data | |
| if: ${{ needs.check_data.outputs.POST_BSKY == 'true' }} | |
| steps: | |
| - name: Echo vars | |
| run: | | |
| echo "Should it post: ${{ needs.check_data.outputs.POST_BSKY }}" | |
| echo "Post text: ${{ needs.check_data.outputs.POST_TEXT }}" | |
| - 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" | |
| sleep 60 | |
| - 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 }} | |