Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/process.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Process newly added JSON

on:
pull_request:
pull_request_target:
types: [closed]
branches:
- main
Expand All @@ -24,8 +24,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Needed to push changes back to the repo
fetch-depth: 0
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 2

# Must be done before setup-node.
- name: Enable Corepack
Expand All @@ -46,11 +46,8 @@ jobs:
id: find-json
run: |
# Get the list of added JSON files in the records/new/ directory
ADDED_FILES=$(git diff ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} --diff-filter=A --name-only | grep '^records/new/.*\.json$' || true)
echo "NEW_JSON_FILES=$ADDED_FILES" >> $GITHUB_ENV
if [ -z "$ADDED_FILES" ]; then
echo "No new JSON files found."
fi
ADDED_FILES=$(git diff HEAD^ --diff-filter=A --name-only records/new | grep '/.*\.json$' || true)
echo "NEW_JSON_FILES=$ADDED_FILES" >> "$GITHUB_ENV"

- name: Process and move files
if: env.NEW_JSON_FILES
Expand All @@ -68,6 +65,6 @@ jobs:
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add records/*
git add records/
git commit -m "Process new JSON files from #${{ github.event.pull_request.number }}" || exit 0
git push
git push origin HEAD:refs/heads/main
4 changes: 2 additions & 2 deletions automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Content automation is done in the form of adding new JSON files to `records/new`
- `"quote-post"`: quote an existing post specified by `"repostURL"`, with new content specified by `"richText"`
- For other fields see the examples under [`records/new`](./records/new).
3. When the PR is opened, the [validate-json](./.github/workflows/validate.yml) workflow will run to make sure the JSON files are correctly filled. It will verify the URLs filled in the JSON files are valid.
4. When the PR is merged, the [process-json](./.github/workflows/process.yml) workflow will run to perform the requested actions, and when it's done, it will move the processed JSON files to `./records/processed` and renamed the file to `YYYY-MM-DD-ID.json` where ID is an incremental ID based on the number of files already processed on that date. It will also add in additional details of the performed actions (e.g. CID and URI of the posted post).
5. When the process workflow is complete (likely within a minute), you should see a commit from the GitHub bot in the main branch moving the JSON file. **Important**: do not delete the PR branch until the process workflow is complete!
4. When the PR is merged (either with _Squash and merge_ or with a merge commit, _Rebase and merge_ is not supported), the [process-json](./.github/workflows/process.yml) workflow will run to perform the requested actions, and when it's done, it will move the processed JSON files to `./records/processed` and renamed the file to `YYYY-MM-DD-ID.json` where ID is an incremental ID based on the number of files already processed on that date. It will also add in additional details of the performed actions (e.g. CID and URI of the posted post).
5. When the process workflow is complete (likely within a minute), you should see a commit from the GitHub bot in the main branch moving the JSON file.

## Set up automation in a repository

Expand Down