-
Notifications
You must be signed in to change notification settings - Fork 3
100 lines (85 loc) · 3.27 KB
/
update-data-json.yml
File metadata and controls
100 lines (85 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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 }}