Skip to content

Commit

Permalink
chore: Make a custom semantic-release action with build step (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
eKoopmans authored Jul 1, 2024
1 parent 5734d5e commit af78233
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
51 changes: 51 additions & 0 deletions .github/actions/semantic-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Semantic Release
description: Deploy using semantic-release
inputs:
DEFAULT_BRANCH:
description: Name of the default release branch
default: main
DRY_RUN:
description: Runs semantic-release with the "--dry-run" flag to simulate a release but not actually do one
default: false
GITHUB_TOKEN:
description: Token to use to update version in 'package.json' and create GitHub release
required: true
NPM:
description: Whether or not to release as an NPM package
default: false
NPM_TOKEN:
description: Token to publish to NPM (not required for CodeArtifact)
outputs:
VERSION:
description: Version of the new release, or empty if release is unchanged
value: ${{ steps.semantic-release.outputs.version }}
runs:
using: composite
steps:
- name: Installing semantic-release
run: |
echo "Installing semantic-release..."
npm install semantic-release@19 @semantic-release/git@10 --no-save
shell: bash
- name: Run semantic-release
id: semantic-release
env:
DEFAULT_BRANCH: ${{ inputs.DEFAULT_BRANCH }}
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
NPM: ${{ inputs.NPM }}
NPM_TOKEN: ${{ inputs.NPM_TOKEN }}
run: |
echo "version=" >> $GITHUB_OUTPUT
if [ ${{ inputs.DRY_RUN }} == true ]; then
echo "Running semantic-release (dry run)..."
npx semantic-release --dry-run -e ./.github/actions/semantic-release/release.config.js
else
OLD_VERSION=$(node -p -e "require('./package.json').version")
echo "Running semantic-release..."
npx semantic-release -e ./.github/actions/semantic-release/release.config.js
NEW_VERSION=$(node -p -e "require('./package.json').version")
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
fi
fi
shell: bash
27 changes: 27 additions & 0 deletions .github/actions/semantic-release/release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const defaultBranch = process.env.DEFAULT_BRANCH || 'main';
const npmPublish = process.env.NPM === 'true';

module.exports = {
"branches": [
defaultBranch
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/github",
[
"@semantic-release/npm",
{
"npmPublish": npmPublish
}
],
"./.github/actions/semantic-release/semantic-release.plugin.build.js",
"@semantic-release/release-notes-generator",
[
"@semantic-release/git",
{
"assets": ["dist", "package.json", "package-lock.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]"
}
]
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { execSync } = require('child_process');

function prepare(pluginConfig, context) {
execSync('npm run build');
}

module.exports = { prepare };
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ jobs:
cache: npm
- name: Install Dependencies
run: npm ci
- name: Build
run: npm run build
- name: Semantic Release
uses: BrightspaceUI/actions/semantic-release@main
uses: ./.github/actions/semantic-release/
with:
GITHUB_TOKEN: ${{ steps.gh-token.outputs.token }}
NPM: true
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"/src",
"/dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/eKoopmans/html2pdf.js.git"
},
"repository": "git@github.com:eKoopmans/html2pdf.js.git",
"keywords": [
"javascript",
"pdf-generation",
Expand Down

0 comments on commit af78233

Please sign in to comment.