Skip to content

push-releases

push-releases #471

name: Fetch Release Attachments
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
workflow_dispatch: # Allow manual triggering
repository_dispatch:
types: [push-releases]
jobs:
fetch-attachments:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# with:
# repository: ${{ github.repository_owner }}/swissairtainer.github.io # Dynamically use the organization of the running workflow
# token: ${{ secrets.REPO_ACCESS_TOKEN }} # Use a personal access token with the correct permissions
- name: Fetch and organize attachments
uses: actions/github-script@v7
with:
github-token: ${{ secrets.SWAT_RELEASES }}
script: |
const fs = require('fs');
const path = require('path');
async function downloadAsset(asset, repo, tag) {
const assetPath = `fw/${repo}/${tag}/${asset.name}`;
console.log(`Preparing to download asset: ${asset.name} from ${repo}/${tag}`);
const response = await github.request('GET ' + asset.url, {
headers: {
'Accept': 'application/octet-stream'
}
});
const dir = path.dirname(assetPath);
if (!fs.existsSync(dir)){
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(assetPath, Buffer.from(response.data));
console.log(`Downloaded: ${assetPath}`);
}
const repos = await github.paginate(github.rest.repos.listForOrg, { org: context.repo.owner });
console.log(`Total repositories fetched: ${repos.length}`);
const privateRepos = repos.filter(repo => repo.private && repo.name.toLowerCase().endsWith('firmware'));
console.log(`Total private repositories fetched: ${privateRepos.length}`);
for (const repo of privateRepos) {
console.log(`Processing repository: ${repo.name}`);
const releases = await github.paginate(github.rest.repos.listReleases, { owner: context.repo.owner, repo: repo.name });
console.log(`Found ${releases.length} releases in ${repo.name}`);
for (const release of releases) {
console.log(`Processing release: ${release.tag_name} for repo: ${repo.name}`);
for (const asset of release.assets) {
await downloadAsset(asset, repo.name, release.tag_name);
}
}
}
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git status
git add .
git status
git diff-index --quiet HEAD || git commit -m "Update release attachments"
git log -1
git push
echo "Changes pushed to the repository."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}