Skip to content

adjust year

adjust year #341

Workflow file for this run

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/[email protected]
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PNPM
uses: pnpm/action-setup@v3
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install Dependencies
run: pnpm i
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
with:
commit: "[ci] release"
title: "[ci] release"
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
prepare-matrix:
name: Prepare Matrix
runs-on: ubuntu-latest
outputs:
repo-matrix: "${{ env.REPO_MATRIX }}"
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- 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, '[ci] release')
)
) ||
github.event_name == 'workflow_dispatch'
steps:
- name: Generate GitHub App token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Checkout current repository
uses: actions/checkout@v4
- name: Setup PNPM
uses: pnpm/action-setup@v3
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
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@v4
with:
name: summary-table-${{ env.SANITIZED_REPO_NAME }}
path: summary/summary_table.txt
- name: Upload summary as artifact
uses: actions/upload-artifact@v4
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@v4
- name: Download summary artifacts
uses: actions/download-artifact@v4
- name: Combine summaries and generate final markdown table
run: |
# Create or append to the final summary file
echo "### Summary of Changes" > final_summary.md
echo "" >> final_summary.md
echo "| Repository | PR Link | Files Changed |" >> final_summary.md
echo "|------------|---------|---------------|" >> final_summary.md
# Loop over the downloaded summary artifacts and append their content
for artifact in $(find . -name "summary_table.txt"); do
cat "$artifact" >> final_summary.md
done
- name: Upload final summary as artifact
uses: actions/upload-artifact@v4
with:
name: final-summary
path: final_summary.md
- name: Combine discord and generate final markdown list
run: |
# Create or append to the final summary file
echo "### Summary of Changes" > discord_summary.md
echo "" >> discord_summary.md
# Loop over the downloaded summary artifacts and append their content
for artifact in $(find . -name "discord_list.txt"); do
cat "$artifact" >> discord_summary.md
done
- name: Upload final summary as artifact
uses: actions/upload-artifact@v4
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@v4
- 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@v4
- id: extract-changelog
uses: sean0x42/[email protected]
with:
file: CHANGELOG.md
pattern: ${{ needs.image-tag.outputs.IMAGE_TAG }}
- name: Download summary artifacts
uses: actions/download-artifact@v4
with:
name: final-summary
- name: Download summary artifacts
uses: actions/download-artifact@v4
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
- name: Discord notification
if: env.RELEASE_SKIPPED == 'false'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
uses: Ilshidur/[email protected]
with:
args: |
# ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }}
${{ steps.extract-changelog.outputs.markdown }}
${{ env.DISCORD_SUMMARY }}