-
Notifications
You must be signed in to change notification settings - Fork 308
ci: Add daily snipsync GitHub workflow #4324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6359196
Add daily snipsync GitHub workflow
lennessyy 4bd5805
temp: add push trigger to snipsync workflow for testing
lennessyy 091c87f
Update .github/workflows/snipsync.yml
lennessyy 5dd22da
Remove temporary push trigger from snipsync workflow
lennessyy b04fda5
Merge branch 'main' into add-snipsync-workflow
lennessyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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: | ||
|
|
||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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