Skip to content

Snipsync

Snipsync #27

Workflow file for this run

name: Snipsync
on:
schedule:
- cron: '0 6 * * *' # Daily at 6:00 UTC
workflow_dispatch:
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 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