-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: build release gh workflow
- Loading branch information
Showing
6 changed files
with
278 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "Extract Version Changelog" | ||
description: "Take the log information from the changelog" | ||
outputs: | ||
VERSION: | ||
description: "The new semver version to be released" | ||
VERSION_LOG: | ||
description: "The log info for the new release" | ||
runs: | ||
using: "node16" | ||
main: "index.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const core = require("@actions/core"), | ||
{ extractChangelogNotesForCurrentVersion } = require("../../../scripts/extractChangeLogNotes"); | ||
|
||
const extractVersionLog = async () => { | ||
try { | ||
console.log("about to retrieve version info from CHANGELOG"); | ||
const { version, versionLog } = await extractChangelogNotesForCurrentVersion(); | ||
|
||
if (!versionLog) { | ||
core.setFailed(`Failed to retrieve log info for ${version}`); | ||
} else { | ||
core.setOutput("VERSION", version); | ||
core.setOutput("VERSION_LOG", versionLog); | ||
|
||
console.log(`Retrieved version ${version} log = `, versionLog); | ||
} | ||
} catch (ex) { | ||
core.setFailed(ex.message); | ||
} | ||
} | ||
|
||
extractVersionLog() | ||
|
||
// github = require("@actions/github"), | ||
//core.getInput('who-to-greet'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,68 +2,190 @@ name: Uploady Release | |
|
||
on: | ||
workflow_dispatch: | ||
branches: | ||
- "release-**" | ||
inputs: | ||
version: | ||
type: choice | ||
description: Which version to release? | ||
required: false | ||
default: "patch" | ||
options: | ||
- "rc" | ||
- "alpha" | ||
- "patch" | ||
- "minor" | ||
- "major" | ||
|
||
branches: | ||
- "release-*" | ||
|
||
#permissions: | ||
# id-token: write | ||
# contents: write | ||
version: | ||
type: choice | ||
description: Which version to release? | ||
required: true | ||
default: "patch" | ||
options: | ||
- "patch" | ||
- "minor" | ||
- "major" | ||
- "prepatch" | ||
- "preminor" | ||
- "premajor" | ||
|
||
preid: | ||
type: choice | ||
description: Which pre-release ID to use? | ||
required: false | ||
default: "" | ||
options: | ||
- "" | ||
- "rc" | ||
- "alpha" | ||
mergeMaster: | ||
type: boolean | ||
description: Merge latest master? | ||
required: true | ||
default: true | ||
|
||
permissions: | ||
# id-token: write | ||
contents: write | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
#working-directory: | ||
|
||
jobs: | ||
Release: | ||
release: | ||
name: Release Uploady | ||
environment: "Release" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16.17" | ||
cache: "yarn" | ||
#cache-dependency-path: "yarn.lock" | ||
|
||
- name: Install Deps | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Prepare | ||
run: yarn bootstrap | ||
|
||
- name: Clean | ||
run: yarn clean | ||
|
||
- name: Define Lerna Args | ||
id: lerna-args | ||
run: | | ||
if [ ${{ inputs.version }} = 'rc' ]; then | ||
echo "VERSION='prerelease --preid rc'" >> $GITHUB_OUTPUT | ||
echo "PUBLISH='--dist-tag next'" >> $GITHUB_OUTPUT | ||
elif [ ${{ inputs.version }} = 'alpha' ] then | ||
echo "PUBLISH='--dist-tag alpha'" >> $GITHUB_OUTPUT | ||
fi | ||
echo "## Version ARGS: ${{ steps.lerna-args.outputs.VERSION }} :rocket:" >> $GITHUB_STEP_SUMMARY | ||
echo "## PUBLISH ARGS: ${{ steps.lerna-args.outputs.PUBLISH }} :rocket:" >> $GITHUB_STEP_SUMMARY | ||
- name: Create Version | ||
run: lerna version ${{ steps.def-version.outputs.VERSION_ARGS }} --force-publish=* --yes | ||
|
||
# - name: Authenticate with Registry | ||
# run: echo "registry=//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc | ||
# env: | ||
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
- name: Check is Pre Release | ||
id: is-pre | ||
if: ${{ inputs.version == 'premajor' || inputs.version == 'preminor' || inputs.version == 'prepatch' }} | ||
run: | | ||
echo "PRE_RELEASE=true" >> $GITHUB_OUTPUT | ||
- name: Validate version with pre-id | ||
if: ${{ steps.is-pre.outputs.PRE_RELEASE == 'true' && inputs.preid == '' }} | ||
run: | | ||
echo "🔴 Failing Job - Cant use (premajor, preminor, prepatch) without selecting PreId too! >> $GITHUB_STEP_SUMMARY | ||
exit 1 | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Define GIT Author | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "Uploady CI" | ||
- name: Merge Latest Master | ||
if: ${{ inputs.mergeMaster == true }} | ||
run: | | ||
git fetch origin | ||
git merge origin/master -m "chore: merge content from master" | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16.17" | ||
cache: "yarn" | ||
#cache-dependency-path: "yarn.lock" | ||
|
||
- name: Install Deps | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Extract Version Changelog | ||
id: version-log | ||
uses: ./.github/actions/versionLog | ||
|
||
- name: Clean | ||
run: yarn clean | ||
|
||
- name: Define Lerna Args | ||
id: lerna-args | ||
run: | | ||
if [ '${{ steps.is-pre.outputs.PRE_RELEASE }} = 'true' }}'] | ||
then | ||
if [ '${{ inputs.preid }}' = 'rc' ] | ||
then | ||
echo "using args for RC release" | ||
echo "VERSION=${{ inputs.version }} --preid rc" >> $GITHUB_OUTPUT | ||
echo "PUBLISH=--dist-tag next" >> $GITHUB_OUTPUT | ||
elif [ '${{ inputs.preid }}' = 'alpha' ] | ||
then | ||
echo "using args for Alpha release" | ||
echo "VERSION=${{ inputs.version }}" >> $GITHUB_OUTPUT | ||
echo "PUBLISH=--dist-tag alpha" >> $GITHUB_OUTPUT | ||
fi | ||
else | ||
echo "using args for ${{ inputs.version }} release" | ||
echo "VERSION=${{ inputs.version }}" >> $GITHUB_OUTPUT | ||
fi | ||
# - name: Create Version | ||
# id: version | ||
# run: | | ||
# echo "### Version ARGS: ${{ steps.lerna-args.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY | ||
# lerna version ${{ steps.lerna-args.outputs.VERSION }} --force-publish=* --no-push --yes | ||
# | ||
# - name: Build Source | ||
# run: yarn build | ||
# | ||
# - name: Bundle Source | ||
# run: yarn bundle:prod | ||
# | ||
# - name: Authenticate with NPM Registry | ||
# run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc | ||
# env: | ||
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
# | ||
# - name: Publish | ||
# id: publish | ||
# run: | | ||
# lerna publish from-package ${{ steps.lerna-args.outputs.PUBLISH }} --no-push --yes | ||
# echo "## Published: ${{ format('v{0}', steps.version-log.outputs.VERSION) }} :rocket:" >> $GITHUB_STEP_SUMMARY | ||
# | ||
# - name: Create GH Release | ||
# uses: ncipollo/release-action@v1 | ||
# with: | ||
# name: ${{ format('v{0}', steps.version-log.outputs.VERSION) }} | ||
# body: ${{ steps.version-log.outputs.VERSION_LOG }} | ||
# #draft: true | ||
# prerelease: ${{ fromJSON(steps.is-pre.outputs.PRE_RELEASE) }} | ||
# tag: ${{ format('v{0}', steps.version-log.outputs.VERSION) }} | ||
# | ||
# - name: Push changes | ||
# if: ${{ always() && steps.version.outcome == 'success' && steps.publish.outcome == 'success' }} | ||
# run: | | ||
# git push --tags | ||
# | ||
# - name: Create PR for Release | ||
# id: pr | ||
# uses: peter-evans/create-pull-request@v5 | ||
# with: | ||
# title: "chore: release ${{ format('v{0}', steps.version-log.outputs.VERSION) }}" | ||
# body: "Automatic PR for release: ${{ format('v{0}', steps.version-log.outputs.VERSION) }}" | ||
# branch: ${{ github.ref }} | ||
# commit-message: "commit new version" | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# - name: Commit changes to GIT | ||
# run: | | ||
# git commit -a -m "chore: release v${{ steps.version-log.outputs.VERSION }}" | ||
# git push | ||
#git tag -a ui-${{ steps.version-bump.outputs.NEW_VERSION }} -m "${{ steps.version-bump.outputs.GIT_PUSH_MSG }}" | ||
#git push origin ui-${{ steps.version-bump.outputs.NEW_VERSION }} | ||
|
||
# echo "## PUBLISH ARGS: ${{ steps.lerna-args.outputs.PUBLISH }} :rocket:" >> $GITHUB_STEP_SUMMARY | ||
|
||
|
||
# uses last commit details: | ||
#"$(git log -n 1 --pretty=format:%an)" | ||
#"$(git log -n 1 --pretty=format:%ae)" | ||
|
||
# - name: Cache node_modules | ||
# id: cache-node-modules | ||
# uses: actions/cache@v3 | ||
# with: | ||
# path: node_modules | ||
# key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }} | ||
# restore-keys: | | ||
# ${{ runner.os }}-${{ matrix.node-version }}-nodemodules- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const fs = require("fs"), | ||
{ logger } = require("./utils"), | ||
MarkDownIt = require("markdown-it"); | ||
|
||
const extractChangelogNotesForVersion = (version) => { | ||
logger.log(`Extracting changes from changelog for version ${version}`); | ||
|
||
let versionLog; | ||
|
||
return new Promise((resolve) => { | ||
fs.readFile("./CHANGELOG.md", { encoding: "UTF-8" }, (err, data) => { | ||
const md = new MarkDownIt(); | ||
const tokens = md.parse(data); | ||
|
||
let startIndex = -1, | ||
endIndex = undefined; | ||
|
||
for (let i = 0; i < tokens.length; i++) { | ||
if (!~startIndex && tokens[i].tag === "h2" | ||
//use space so pre-release isn't matched against non-pre-release | ||
&& tokens[i + 1]?.content.startsWith(version + " ")) { | ||
startIndex = i | ||
} else if (!!~startIndex && tokens[i].tag === "h2" && tokens[i].type === "heading_open") { | ||
endIndex = i - 1; | ||
break; | ||
} | ||
} | ||
|
||
if (!!~startIndex) { | ||
const relevantTokens = tokens.slice(startIndex, (endIndex)); | ||
|
||
versionLog = relevantTokens.map((t) => | ||
(t.type === "heading_open" ? "\n" : "") + | ||
(!["list_item_close", "heading_close", "bullet_list_open", "bullet_list_close"].includes(t.type) ? t.markup : "") + | ||
(t.content && ` ${t.content}\n`) + | ||
(t.type === "heading_close" ? "\n" : "") | ||
).join(""); | ||
|
||
logger.verbose(`___ Version (${version}) Changelog ___\n\n${versionLog}\n\n`); | ||
} | ||
|
||
resolve(versionLog); | ||
}); | ||
}); | ||
}; | ||
|
||
const extractChangelogNotesForCurrentVersion = async () => { | ||
const lernaJson = require("../lerna.json"); | ||
const version = lernaJson.version; | ||
|
||
const versionLog = await extractChangelogNotesForVersion(version); | ||
|
||
return { version, versionLog }; | ||
}; | ||
|
||
module.exports = { | ||
extractChangelogNotesForCurrentVersion, | ||
extractChangelogNotesForVersion, | ||
}; | ||
|
Oops, something went wrong.