feat: do not request review but assign sync PRs instead #551
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
| name: Update Template Files Across Repos | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| env: | |
| IMAGE_NAME: template-files | |
| jobs: | |
| changesets: | |
| name: Changesets | |
| runs-on: ubuntu-latest | |
| outputs: | |
| hasChangesets: ${{ steps.changesets.outputs.hasChangesets }} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Generate GitHub App token | |
| id: generate_token | |
| uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 | |
| with: | |
| app_id: ${{ secrets.BOT_APP_ID }} | |
| private_key: ${{ secrets.BOT_PRIVATE_KEY }} | |
| - name: Checkout Repo | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup PNPM | |
| uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 | |
| - name: Setup Node | |
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | |
| with: | |
| node-version: 24.11.1 | |
| cache: "pnpm" | |
| - name: Install Dependencies | |
| run: pnpm i | |
| - name: Create Release Pull Request | |
| uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3 | |
| id: changesets | |
| with: | |
| version: pnpm run version | |
| commit: "ci: release" | |
| title: "ci: release [skip netlify]" | |
| env: | |
| GITHUB_TOKEN: ${{ steps.generate_token.outputs.token}} | |
| - name: Get published version | |
| if: steps.changesets.outputs.hasChangesets == 'true' | |
| run: | | |
| git checkout changeset-release/main | |
| VERSION=$(node -p "require('./package.json').version") | |
| git commit --amend -m "ci: release ${{ env.IMAGE_NAME }} v$VERSION" --no-edit | |
| git push origin changeset-release/main:changeset-release/main --force | |
| prepare-matrix: | |
| name: Prepare Matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| repo-matrix: "${{ env.REPO_MATRIX }}" | |
| steps: | |
| - name: Checkout current repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| - name: Install jq | |
| run: sudo apt-get install -y jq | |
| - name: Read Repositories from JSON | |
| id: set-matrix | |
| run: | | |
| repos="$(jq -c '.repositories[] | {name: .name, files: .files}' repos.json | jq -s .)" | |
| { | |
| echo "REPO_MATRIX<<EOF" | |
| echo "${repos}" | |
| echo EOF | |
| } >> $GITHUB_ENV | |
| - name: Print Matrix | |
| run: echo "${{ env.REPO_MATRIX }}" | |
| sync: | |
| runs-on: ubuntu-latest | |
| needs: [changesets, prepare-matrix] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| repo: "${{ fromJson(needs.prepare-matrix.outputs.repo-matrix) }}" | |
| if: > | |
| ( | |
| needs.changesets.outputs.hasChangesets == 'false' && | |
| ( | |
| contains(github.event.head_commit.message, 'deploy') || | |
| contains(github.event.head_commit.message, 'release') | |
| ) | |
| ) || | |
| github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Generate GitHub App token | |
| id: generate_token | |
| uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 | |
| with: | |
| app_id: ${{ secrets.BOT_APP_ID }} | |
| private_key: ${{ secrets.BOT_PRIVATE_KEY }} | |
| - name: Checkout current repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| - name: Setup PNPM | |
| uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 | |
| - name: Setup Node | |
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | |
| with: | |
| node-version: 24.11.1 | |
| cache: "pnpm" | |
| - name: Install jq, sort-package-json and markdown-replace-section | |
| run: | | |
| sudo apt-get install -y jq | |
| npm install -g sort-package-json | |
| npm install -g markdown-replace-section | |
| - name: Ensure "🤖 bot" label exists | |
| env: | |
| GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
| run: | | |
| # Check if label exists in target repository, create if not | |
| if ! gh label list -R "${{ matrix.repo.name }}" | grep -q "🤖 bot"; then | |
| gh label create "🤖 bot" \ | |
| --description "Automatically generated pull request" \ | |
| --color "0075ca" \ | |
| -R "${{ matrix.repo.name }}" | |
| fi | |
| - name: Run synchronization script | |
| env: | |
| GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
| REPO_NAME: ${{ matrix.repo.name }} | |
| FILES: ${{ toJson(matrix.repo.files) }} | |
| run: ./sync_templates.sh | |
| - name: Append summary for repository | |
| if: success() | |
| env: | |
| GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
| run: | | |
| repo_name="${{ matrix.repo.name }}" | |
| branch_name="update-template-files" | |
| pr_url="https://github.com/${repo_name}/pull/$(gh pr list --repo "$repo_name" --base main --head "$branch_name" --json number --jq '.[0].number')" | |
| changed_files="${{ env.CHANGED_FILES }}" | |
| mkdir -p "summary" | |
| mkdir -p "discord" | |
| if [ "$changed_files" -gt 0 ]; then | |
| echo "| $repo_name | [PR Link]($pr_url) | $changed_files |" >> summary/summary_table.txt | |
| if [ "$changed_files" -eq 1 ]; then | |
| echo "- $repo_name -- $changed_files file changed: ([PR Link]($pr_url))" >> discord/discord_list.txt | |
| else | |
| echo "- $repo_name -- $changed_files files changed: ([PR Link]($pr_url))" >> discord/discord_list.txt | |
| fi | |
| else | |
| echo "| $repo_name | No PR | $changed_files |" >> summary/summary_table.txt | |
| echo "- $repo_name -- No files changed" >> discord/discord_list.txt | |
| fi | |
| - name: Replace "/" with "-" in repo name for artifact upload | |
| run: | | |
| repo_name="${{ matrix.repo.name }}" | |
| sanitized_repo_name="${repo_name//\//-}" | |
| echo "Sanitized repo name: $sanitized_repo_name" | |
| echo "SANITIZED_REPO_NAME=$sanitized_repo_name" >> $GITHUB_ENV | |
| - name: Upload summary as artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: summary-table-${{ env.SANITIZED_REPO_NAME }} | |
| path: summary/summary_table.txt | |
| - name: Upload summary as artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: discord-list-${{ env.SANITIZED_REPO_NAME }} | |
| path: discord/discord_list.txt | |
| summarize: | |
| name: Synchronization Report | |
| runs-on: ubuntu-latest | |
| needs: sync | |
| steps: | |
| - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| - name: Download summary artifacts | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| - name: Combine summaries and generate final markdown table | |
| run: | | |
| # Combine and sort summary tables alphabetically by repo name | |
| find . -name "summary_table.txt" -exec cat {} + | sort -t'|' -k2,2 > sorted_summary.txt | |
| # Write header and sorted content | |
| { | |
| echo "### Summary of Changes" | |
| echo "" | |
| echo "| Repository | PR Link | Files Changed |" | |
| echo "|------------|---------|---------------|" | |
| cat sorted_summary.txt | |
| } > final_summary.md | |
| - name: Upload final summary as artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: final-summary | |
| path: final_summary.md | |
| - name: Combine discord and generate final markdown list | |
| run: | | |
| # Combine and sort Discord summaries alphabetically by repo name | |
| find . -name "discord_list.txt" -exec cat {} + | sort -t'-' -k2,2 > sorted_discord.txt | |
| { | |
| echo "### Summary of Changes" | |
| echo "" | |
| cat sorted_discord.txt | |
| } > discord_summary.md | |
| - name: Upload final summary as artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: discord-summary | |
| path: discord_summary.md | |
| - name: Display summary in the GitHub Actions summary | |
| run: | | |
| if [ -f final_summary.md ]; then | |
| cat final_summary.md >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "No data collected" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| image-tag: | |
| name: Image Tag | |
| runs-on: ubuntu-latest | |
| outputs: | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| - name: Read version from package.json | |
| id: get_version | |
| run: | | |
| VERSION=$(jq -r '.version' package.json) | |
| echo "IMAGE_TAG=$VERSION" >> $GITHUB_ENV | |
| release: | |
| name: Release | |
| needs: [sync, image-tag, summarize] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| - id: extract-changelog | |
| uses: sean0x42/markdown-extract@7b185cbe85263116bbf741e739e7198ba86465dc # v2.1.0 | |
| with: | |
| file: CHANGELOG.md | |
| pattern: ${{ needs.image-tag.outputs.IMAGE_TAG }} | |
| - name: Download summary artifacts | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: final-summary | |
| - name: Download summary artifacts | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: discord-summary | |
| - name: Save summary into Github environment variable | |
| run: | | |
| { | |
| echo "SYNC_SUMMARY<<EOF" | |
| cat final_summary.md | |
| echo "EOF" | |
| } >> $GITHUB_ENV | |
| { | |
| echo "DISCORD_SUMMARY<<EOF" | |
| cat discord_summary.md | |
| echo "EOF" | |
| } >> $GITHUB_ENV | |
| - uses: ncipollo/release-action@v1 | |
| id: create_release | |
| with: | |
| tag: ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }} | |
| makeLatest: true | |
| body: | | |
| ${{ steps.extract-changelog.outputs.markdown }} | |
| ${{ env.SYNC_SUMMARY }} | |
| skipIfReleaseExists: true | |
| - name: Check if release was created | |
| id: check_release | |
| run: | | |
| if [ -z "${{ steps.create_release.outputs.html_url }}" ]; then | |
| echo "RELEASE_SKIPPED=true" >> $GITHUB_ENV | |
| else | |
| echo "RELEASE_SKIPPED=false" >> $GITHUB_ENV | |
| fi |