Skip to content

Commit

Permalink
chore: update release strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
marksie1988 committed Aug 24, 2023
1 parent 7e646ad commit 7f4acc6
Show file tree
Hide file tree
Showing 5 changed files with 1,472 additions and 1,423 deletions.
82 changes: 15 additions & 67 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,28 @@
name: release
name: Release

on:
push:
branches:
- main
workflow_dispatch:
- master # Change this to your main branch name

jobs:
release:
name: Create release
runs-on: ubuntu-latest
steps:
- name: Getting your configuration from GitHub
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14

- name: Install dependencies
run: yarn install

- name: Check if TypeScript files changed
id: check-ts-changes
run: echo ::set-output name=changed::$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '\.ts$' | wc -l)

- name: Get latest tag
id: get-latest-tag
run: echo ::set-output name=latest_tag::$(git describe --tags --abbrev=0 | sed 's/^v//')

- name: Get current version
id: get-version
run: echo ::set-output name=version::$(node -pe "require('./package.json').version")

- name: Check if version is higher
id: check-version
run: echo ::set-output name=is_higher::$(node -pe "const semver = require('semver'); semver.gt('${{ steps.get-version.outputs.version }}', '${{ steps.get-latest-tag.outputs.latest_tag }}')")

- name: Check if semver label is valid
id: check-semver
if: steps.check-ts-changes.outputs.changed == 'true'
run: |
const labelsInput = ${{ toJSON(github.event.pull_request.labels) }};
const currentVersion = ${{ steps.get-version.outputs.version }};
const isMajor = labelsInput.some(label => label.name === 'semver/major' || label.name === 'type/breaking');
const isMinor = labelsInput.some(label => label.name === 'semver/minor' || label.name === 'type/feature);
const isPatch = labelsInput.some(label => label.name === 'semver/patch' || label.name === 'type/bug);
steps:
- name: Checkout code
uses: actions/checkout@v2

const isSemverValid = () => {
if (isMajor) {
return currentVersion.includes('0.0.0');
} else if (isMinor) {
return currentVersion.includes('0.0.');
} else if (isPatch) {
return currentVersion.includes('0.');
} else {
return false
}
};
echo ::set-output name=is_valid::$(isSemverValid)
- name: Setup Node.js
uses: actions/setup-node@v2

- name: Build project
if: steps.check-ts-changes.outputs.changed == 'true' && steps.check-semver.outputs.is_valid == 'true' && steps.check-version.outputs.is_higher == 'true'
run: yarn run build
- name: Install dependencies
run: yarn install

- name: 🛎️ Create release
if: steps.check-ts-changes.outputs.changed == 'true' && steps.check-semver.outputs.is_valid == 'true' && steps.check-version.outputs.is_higher == 'true'
uses: softprops/action-gh-release@v1
with:
files: dist/atomic-calendar-revive.js
tag_name: ${{ steps.get-version.outputs.version }}
name: Release ${{ steps.get-version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
generate_release_notes: true
- name: Build
run: yarn run build

- name: 🏷️ Update latest tag
if: steps.check-ts-changes.outputs.changed == 'true' && steps.check-semver.outputs.is_valid == 'true' && steps.check-version.outputs.is_higher == 'true'
uses: EndBug/latest-tag@latest
- name: Run Semantic Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dist/*
!.devcontainer/recommended-devcontainer.json
!.devcontainer/recommended-Dockerfile
!.devcontainer/post-install.sh
dist

.vscode/*

Expand Down
1,331 changes: 0 additions & 1,331 deletions dist/atomic-calendar-revive.js

This file was deleted.

35 changes: 34 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"babel-preset-minify": "^0.5.2",
Expand All @@ -47,7 +49,8 @@
"prettier": "^3.0.2",
"rollup": "^3.28.1",
"rollup-plugin-serve": "^2.0.2",
"rollup-plugin-typescript2": "^0.35.0"
"rollup-plugin-typescript2": "^0.35.0",
"semantic-release": "^21.1.1"
},
"dependencies": {
"@formatjs/icu-messageformat-parser": "^2.6.0",
Expand Down Expand Up @@ -84,5 +87,35 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"release": {
"branches": [
"main"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/changelog",
[
"@semantic-release/git",
{
"assets": [
"dist/atomic-calendar-revive.js"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
]
}
}
Loading

0 comments on commit 7f4acc6

Please sign in to comment.