Skip to content
Merged
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
83 changes: 83 additions & 0 deletions .github/workflows/snipsync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Snipsync

on:
schedule:
- cron: '0 6 * * *' # Daily at 6:00 UTC
workflow_dispatch:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it just adds the "Run workflow" button in the Actions tab with no required field so we can run it by hand if we ever need to


jobs:
snipsync:
name: Sync code snippets
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.TEMPORAL_CICD_APP_ID }}
private-key: ${{ secrets.TEMPORAL_CICD_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ steps.generate_token.outputs.token }}
ref: main

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run snipsync
run: yarn snipsync

- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi

- name: Commit and push changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

branch_name="snipsync/daily-update"
git checkout -B "$branch_name"
git add docs/
git commit -m "chore: sync code snippets via snipsync"
git push --force-with-lease origin "$branch_name"

- name: Create or update PR
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
branch_name="snipsync/daily-update"
existing_pr=$(gh pr list --head "$branch_name" --state open --json number --jq '.[0].number')

if [ -n "$existing_pr" ]; then
echo "PR #$existing_pr already exists — updated with latest push."
else
gh pr create \
--title "chore: sync code snippets" \
--body "$(cat <<'EOF'
Automated daily sync of code snippets from source repositories via snipsync.

This PR was generated by the [Snipsync workflow](https://github.com/${{ github.repository }}/actions/workflows/snipsync.yml).
EOF
)" \
--head "$branch_name" \
--base "main"
fi
Loading