Skip to content

Sync Release Assets #2991

Sync Release Assets

Sync Release Assets #2991

---
name: Sync Release Assets
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
env:
MAX_NEW_ASSETS: 50 # Set to 0 for unlimited, or any positive number to limit downloads per run
on:
workflow_dispatch:
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize
push:
branches:
- master
schedule:
- cron: '0 * * * *'
jobs:
sync-assets:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.GH_BOT_TOKEN }}
- name: Create or checkout dist branch into dist directory
run: |
git fetch origin
if git rev-parse --verify origin/dist >/dev/null 2>&1; then
echo "Dist branch exists, checking it out"
git worktree add dist origin/dist
cd dist
git pull origin dist
else
echo "Dist branch doesn't exist, creating new one"
git worktree add --orphan dist
cd dist
git rm -rf . 2>/dev/null || true
fi
- name: Get organization repositories and download assets
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
// Import the sync assets with metadata module
const { syncAssetsWithMetadata } = require('./.github/scripts/sync-assets-with-metadata.js');
// Check if this is a pull request event
const isPullRequest = context.eventName === 'pull_request';
// Get the max new assets limit from environment
const maxNewAssets = parseInt(process.env.MAX_NEW_ASSETS) || 0;
// Change working directory to dist for file operations
process.chdir('./dist');
// Run the asset synchronization and store metadata
await syncAssetsWithMetadata(github, context, isPullRequest, maxNewAssets);
- name: Generate packages.json
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
// Import the packages generation module
const { generatePackagesWithCleanup } = require('./.github/scripts/generate-packages-with-cleanup.js');
console.log('Generating packages.json from dist directory...');
// Change to dist directory
process.chdir('./dist');
// Generate packages.json with cleanup
generatePackagesWithCleanup('.');
- name: Commit and push changes
if: github.event_name != 'pull_request'
uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # v1.5
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
branch: dist
directory: dist
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: 'Update release assets - ${{ github.run_id }}'