Skip to content

Commit

Permalink
Simplify releaser code, add it to yarn workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
niallthomson committed Dec 20, 2024
1 parent 14b7c4e commit 1e28393
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 362 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
permissions:
id-token: write
contents: write
issues: read

jobs:
build:
Expand All @@ -22,14 +23,16 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: Release
working-directory: releaser
- name: Release Notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MILESTONE_NUMBER: "${{ github.event.milestone.number }}"
run: |
npm install
npm run exec
yarn install
yarn workspace releaser run exec
MILESTONE_TITLE=$(gh api "repos/$GITHUB_REPOSITORY/milestones/$MILESTONE_NUMBER" --jq '.title')
echo "MILESTONE_TITLE=$MILESTONE_TITLE" >> $GITHUB_ENV
- name: Set Git config
run: |
git config user.name 'github-actions[bot]'
Expand Down Expand Up @@ -62,3 +65,9 @@ jobs:
BRANCH: ${{ env.SNAPSHOT_BRANCH }}
run: |
bash hack/publish-snapshot.sh
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
tag: release-${{ env.SNAPSHOT_BRANCH }}
name: ${{ env.MILESTONE_TITLE }}
bodyFile: /tmp/release-notes.md
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"private": true,
"workspaces": [
"website"
"website",
"releaser"
],
"scripts": {
"serve": "yarn workspace website serve",
Expand Down
25 changes: 8 additions & 17 deletions releaser/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "@octokit/rest";
import fs from "fs/promises";

const CATEGORIES = [
{
Expand Down Expand Up @@ -56,15 +57,12 @@ function generateMarkdown(entries) {

async function main() {
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 { owner, repo } = parseRepositoryString(repository);

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

const octokit = new Octokit({
auth,
});
Expand Down Expand Up @@ -131,20 +129,13 @@ async function main() {

let output = generateMarkdown(entries);

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,
});
try {
await fs.writeFile("/tmp/release-notes.md", output, "utf8");
console.log("Successfully wrote release notes to /tmp/release-notes.md");
} catch (error) {
console.error("Error writing release notes file:", error);
throw error;
}
}

await main();
Loading

0 comments on commit 1e28393

Please sign in to comment.