Skip to content

Commit

Permalink
Add new release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
niallthomson committed Oct 28, 2023
1 parent aaa8f8b commit 853e103
Show file tree
Hide file tree
Showing 4 changed files with 503 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release
on:
milestone:
types: [closed]

permissions:
id-token: write
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
submodules: recursive
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Release
working-directory: releaser
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MILESTONE_NUMBER: "${{ github.event.milestone.number }}"
run: |
npm install
npm run exec
- name: Set Git config
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Update stable branch
run: |
git fetch --unshallow
git checkout stable
git pull
git merge --no-ff main -m "Publish to stable"
git push
108 changes: 108 additions & 0 deletions releaser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Octokit } from "@octokit/rest";

let repository = process.env.GITHUB_REPOSITORY
let sha = process.env.GITHUB_SHA
let milestoneNumber = process.env.MILESTONE_NUMBER

let auth = process.env.GITHUB_TOKEN

let repositoryParts = repository.split('/');
let owner = repositoryParts[0];
let repo = repositoryParts[1];

let tagName = `release-${Math.floor(Date.now() / 1000)}`

const octokit = new Octokit({
auth
});

const categories = [{
title: "## 🚀 New labs",
label: 'new'
}, {
title: "## ✨ Updated labs",
label: 'update'
}, {
title: "## 🐛 Fixes",
label: 'fix'
}, {
title: "## 🧪 Features",
label: 'feat'
}]

let entries = {};

let milestone = await octokit.rest.issues.getMilestone({
owner,
repo,
milestone_number: milestoneNumber,
});

for await (const response of octokit.paginate.iterator(
octokit.rest.pulls.list,
{
owner,
repo,
state: 'closed'
},
)) {
response.data.forEach((e) => {
if(e.milestone) {
if(e.milestone.number == milestoneNumber) {
categories.forEach((c) => {
let targetPrefix = `${c.label}:`;

if(e.title.indexOf(targetPrefix) == 0) {
if(!entries[c.title]) {
entries[c.title] = [];
}

entries[c.title].push({
number: e.number,
title: e.title.substring(targetPrefix.length + 1),
url: e.html_url,
author: {
login: e.user.login,
url: e.user.html_url,
}
});
}
})
}
}
})
}

let output = '';

categories.forEach((c) => {
let categoryOutput = `${c.title}
`;
if(entries[c.title]) {
let categoryEntries = entries[c.title];

if(categoryEntries.length > 0) {
categoryEntries.forEach((e) => {
categoryOutput += `- ${e.title} by [@${e.author.login}](${e.author.url}) ([#${e.number}](${e.url}))\n`
});

output += `${categoryOutput} \n`;
}
}
});

await octokit.rest.git.createRef({
owner,
repo,
ref: `refs/tags/${tagName}`,
sha,
});

await octokit.rest.repos.createRelease({
owner,
repo,
tag_name: tagName,
name: milestone.data.title,
body: output
});
Loading

0 comments on commit 853e103

Please sign in to comment.