Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bastosmichael/ac3f09de22ca47bbd7451093846727f7 to your computer and use it in GitHub Desktop.
Save bastosmichael/ac3f09de22ca47bbd7451093846727f7 to your computer and use it in GitHub Desktop.
Weekly Automated Release for any repository
name: Weekly Release
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
permissions:
contents: write
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Create weekly release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { repo, owner } = context.repo;
let lastReleaseDate = new Date(0);
try {
const latestRelease = await github.rest.repos.getLatestRelease({
owner,
repo
});
lastReleaseDate = new Date(latestRelease.data.created_at);
} catch (error) {
core.info('No previous release found');
}
const lastWeek = new Date();
lastWeek.setDate(lastWeek.getDate() - 7);
const sinceDate = lastReleaseDate > lastWeek ? lastReleaseDate : lastWeek;
const commits = await github.paginate(
github.rest.repos.listCommits,
{
owner,
repo,
since: sinceDate.toISOString(),
sha: 'main'
}
);
if (commits.length === 0) {
core.info('No new commits since last release');
return;
}
const tag = `${new Date().toISOString().slice(0, 10)}`;
await github.rest.repos.createRelease({
owner,
repo,
tag_name: tag,
name: `Release ${tag}`,
target_commitish: 'main',
generate_release_notes: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment