Skip to content

Commit

Permalink
chore(workflow): rework the release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gcornut committed Sep 3, 2024
1 parent 1d3ce12 commit 3ea864c
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 259 deletions.
7 changes: 1 addition & 6 deletions .github/actions/release-note/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
name: 'Release note'
description: 'Create GitHub release with autogenerated notes (coming from the CHANGELOG)'

inputs:
versionTag:
description: The version tag for the release
required: true

runs:
using: composite
steps:
- uses: actions/github-script@v6
with:
script: |
const main = require('.github/actions/release-note/index.js');
await main({ versionTag: '${{ inputs.versionTag}}', context, github });
await main({ context, github });
19 changes: 10 additions & 9 deletions .github/actions/release-note/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ async function getLatestVersionChangelog() {
/**
* Generate release note and create a release on GH.
*/
async function main({ versionTag, github, context }) {
const [{ version, versionChangelog }, storybookURL] = await Promise.all([
getLatestVersionChangelog(),
getStoryBookURL(versionTag),
]);
async function main({ github, context }) {
const storybookURLPromise = getStoryBookURL(context.sha);
const { version, versionChangelog } = await getLatestVersionChangelog();
const versionTag = `v${version}`;

// Related links
const changelogURL = `https://github.com/lumapps/design-system/blob/${versionTag}/CHANGELOG.md`;
const storyBookURL = await storybookURLPromise;
const links = `[🎨 StoryBook](${storyBookURL}) - [📄 See changelog history](${changelogURL})`;

// Release notes
const body = `### [🎨 StoryBook](${storybookURL})\n\n### [📄 Changelog](${changelogURL})\n\n${versionChangelog}`;
const body = `${versionChangelog}\n\n${links}`;

await github.rest.repos.createRelease({
draft: false,
Expand All @@ -40,7 +42,7 @@ async function main({ versionTag, github, context }) {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: versionTag,
name: `v${version}`,
name: versionTag,
body,
});
}
Expand All @@ -49,8 +51,7 @@ module.exports = main;

// Example use (run with `node .github/actions/release-note/index.js`)
if (require.main === module) main({
versionTag: 'v3.0.5',
context: { repo: { repo: 'design-system', owner: 'lumapps' } },
context: { repo: { repo: 'design-system', owner: 'lumapps' }, sha: 'cdde1f3d1' },
// Mocked GH API
github: { rest: { repos: { createRelease: console.log } } },
});
6 changes: 3 additions & 3 deletions .github/actions/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const util = require('util');
const exec = util.promisify(require('child_process').exec);

/**
* Get short SHA for git ref.
*/
async function getShortSHA(gitRef) {
const util = require('util');
const exec = util.promisify(require('child_process').exec);

return exec(`git rev-parse --short ${gitRef}`)
.then(({ stdout }) => stdout.trim());
}
Expand Down
68 changes: 0 additions & 68 deletions .github/workflows/release-build-site.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/workflows/release-deploy-chromatic.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/release-github-release-note.yml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/release-prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: "Prepare Release Workflow"

# Manual trigger workflow to automatically setup a new release PR (built & publish on merge)

on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major

concurrency:
group: "${{ github.workflow }}-${{ github.ref_name }}"
cancel-in-progress: true

jobs:
prepare_release:
name: "Prepare Release"
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
with:
token: ${{ secrets.GITBOT_TOKEN }}
fetch-depth: 0

- name: "Setup"
uses: ./.github/actions/setup

- name: "Increment package versions"
id: version
uses: ./.github/actions/increment-package-versions
with:
releaseType: '${{ inputs.releaseType }}'

- name: "Check build libs"
run: yarn build:libs

- name: "Git commit & push"
id: git
run: |
set -x # verbose
git config --global user.name "lumbot"
git config --global user.email "[email protected]"
# Commit
commit="chore(release): release v${{ steps.version.outputs.nextVersion }}"
echo "commit=$commit" >> $GITHUB_OUTPUT
git commit -am "$commit"
# Push
git push origin "${{ steps.version.outputs.releaseBranch }}"
- name: "Create pull request"
uses: actions/github-script@v6
with:
github-token: '${{ secrets.GITBOT_TOKEN }}'
script: |
github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'master',
head: '${{ steps.version.outputs.releaseBranch }}',
title: '${{ steps.git.outputs.commit }}',
body: '# Release v${{ steps.version.outputs.nextVersion }}\n\n'
+ 'Review, test and merge to publish to NPM.\n\n'
+ 'Triggered by @${{ github.actor }}',
draft: false,
});
Loading

0 comments on commit 3ea864c

Please sign in to comment.