Skip to content

Fetch release data

Fetch release data #93

Workflow file for this run

name: Fetch release data
# Refreshes data/releases.json from the GitHub Releases API and commits it back
# to the repo when anything changed. Runs daily, on push to main, and on demand.
on:
schedule:
- cron: '0 6 * * *' # daily at 06:00 UTC
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
concurrency:
group: fetch-data
cancel-in-progress: false
jobs:
fetch:
runs-on: ubuntu-latest
# Skip the run that our own "[bot] update release data" push would trigger,
# so the commit below cannot loop back into another fetch.
if: github.event_name != 'push' || github.actor != 'github-actions[bot]'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch releases and write data/releases.json
uses: actions/github-script@v7
with:
# github-script provides an authenticated Octokit using GITHUB_TOKEN.
script: |
const fs = require('fs');
// owncloud org repos and how many recent stable releases to keep each.
const REPOS = [
{ key: 'ocis', repo: 'ocis', count: 3 },
{ key: 'client', repo: 'client', count: 2 },
{ key: 'android', repo: 'android', count: 1 },
{ key: 'ios', repo: 'ios-app', count: 1 },
];
const stripBody = (body) => {
if (!body) return '';
return body
.replace(/\r\n/g, '\n')
.replace(/\r/g, '\n')
.split('\n')
.filter((line) => !line.trimStart().startsWith('#')) // drop markdown headers
.join(' ')
.replace(/\s+/g, ' ')
.trim()
.slice(0, 300);
};
const shape = (r) => ({
tag_name: r.tag_name,
name: r.name || r.tag_name,
published_at: r.published_at,
html_url: r.html_url,
body: stripBody(r.body),
assets: (r.assets || []).map((a) => ({
name: a.name,
browser_download_url: a.browser_download_url,
size: a.size,
})),
});
const out = { generated_at: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z') };
for (const { key, repo, count } of REPOS) {
const releases = await github.rest.repos.listReleases({
owner: 'owncloud',
repo,
per_page: 30,
});
out[key] = releases.data
.filter((r) => !r.draft && !r.prerelease) // headline must be a stable release
.slice(0, count)
.map(shape);
core.info(`${key}: ${out[key].map((r) => r.tag_name).join(', ') || '(none)'}`);
}
fs.mkdirSync('data', { recursive: true });
fs.writeFileSync('data/releases.json', JSON.stringify(out, null, 2) + '\n');
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ -n "$(git status --porcelain data/releases.json)" ]; then
git add data/releases.json
git commit -m "[bot] update release data"
git push
else
echo "No changes to release data."
fi