Skip to content

Commit

Permalink
ci: update workflows to allow version and preid set via inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ju-Skinner committed Oct 2, 2023
1 parent 1781c5c commit 84fa0b9
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 28 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/actions/publish-npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
default: './'
description: 'A folder containing a package.json file.'

preid:
default: ''
description: 'The prerelease id used when doing a prerelease.'

project:
description: 'The name of the project based on Nx naming.'

Expand Down Expand Up @@ -35,7 +39,7 @@ runs:
shell: bash

- name: Update Version
run: npx lerna version ${{ inputs.version }} --yes --exact --no-changelog --no-push --no-git-tag-version
run: npx lerna version ${{ inputs.version }} --yes --exact --no-changelog --no-push --no-git-tag-version --preid=${{ inputs.preid }}
shell: bash
working-directory: ${{ inputs.working-directory }}

Expand All @@ -50,6 +54,6 @@ runs:
NPM_TOKEN: ${{ inputs.token }}

- name: Publish to NPM
run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }} --provenance
run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }} --provenance --access public
shell: bash
working-directory: ${{ inputs.working-directory }}
35 changes: 28 additions & 7 deletions .github/workflows/icon-export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ name: 'Run Icon Update'
on:
workflow_call:
inputs:
preid:
description: 'The prerelease id used when doing a prerelease.'
type: string
default: ''

tag:
description: 'The tag to publish to NPM'
type: string
default: latest

version:
description: The type of version to release.
type: string

secrets:
FIGMA_ACCESS_TOKEN:
description: "The personal access token created in Figma"
Expand All @@ -21,7 +30,10 @@ jobs:
update-icons:
runs-on: ubuntu-latest
outputs:
bumpType: ${{ steps.version-bump.outputs.VERSION_BUMP_TYPE}}
versionInfo: ${{ steps.version-type-info.outputs.VERSION_INFO }}
nextVersionType: ${{ steps.split-version-info.outputs._0 }}
preid: ${{ steps.split-version-info.outputs._1 }}

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -30,7 +42,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x

- name: Configure user
run: |
Expand Down Expand Up @@ -66,19 +78,28 @@ jobs:
FIGMA_ACCESS_TOKEN: ${{ secrets.FIGMA_ACCESS_TOKEN }}
FIGMA_FILE_ID: ${{ secrets.FIGMA_FILE_ID }}

- name: Determine Major or Minor version bump
id: version-bump
- name: Determine next version type
id: version-type-info
run: |
echo "VERSION_BUMP_TYPE=$(node ./.scripts/update-icon-version.js)" >> $GITHUB_OUTPUT
echo "VERSION_INFO=$(node ./.scripts/update-icon-version.js '${{ inputs.version }}' '${{ inputs.preid }}')" >> $GITHUB_OUTPUT
shell: bash

- name: Split version info
uses: xom9ikk/split@v1.1
id: split-version-info
with:
string: ${{ steps.version-type-info.outputs.VERSION_INFO }}
separator: ','
limit: 2

release:
needs: update-icons
uses: ./.github/workflows/release-icons.yml
if: needs.update-icons.outputs.bumpType != 'none'
if: ${{ needs.update-icons.outputs.nextVersionType != '' }}
with:
preid: ${{ needs.update-icons.outputs.preid }}
tag: ${{ inputs.tag }}
version: ${{ needs.update-icons.outputs.bumpType }}
version: ${{ needs.update-icons.outputs.nextVersionType }}
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

36 changes: 35 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,44 @@ on:
schedule:
- cron: '00 11 * * 1-5' # 11 am UTC Mon-Fri
workflow_dispatch:
inputs:
preid:
type: choice
description: Which prerelease id should be used? This is only needed when a version is "prepatch", "preminor", "premajor", or "prerelease".
options:
- ''
- alpha
- beta
- rc
- next

tag:
type: choice
required: true
description: Which npm tag should this be published to
options:
- latest
- next
- dev

version:
type: choice
required: true
description: Which version should be published?
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease

jobs:
export-icons:
uses: ./.github/workflows/icon-export.yml
with:
tag: nightly
preid: ${{ inputs.preid || '' }}
tag: ${{ inputs.tag || 'nightly' }}
version: ${{ inputs.version || '' }}
secrets: inherit
9 changes: 8 additions & 1 deletion .github/workflows/release-icons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: 'Release Icons'
on:
workflow_call:
inputs:
preid:
description: 'The prerelease id used when doing a prerelease. e.g prerelease, premajor, preminor, etc'
type: string
default: ''

tag:
description: 'The tag to publish on NPM.'
required: true
Expand All @@ -20,6 +25,8 @@ on:
jobs:
release-icons:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -31,8 +38,8 @@ jobs:
- name: Publish Icons
uses: ./.github/workflows/actions/publish-npm
with:
preid: ${{ inputs.preid }}
project: 'icons'
scope: '@pine-ds/icons'
tag: ${{ inputs.tag }}
token: ${{ secrets.NPM_TOKEN }}
version: ${{ inputs.version }}
Expand Down
37 changes: 20 additions & 17 deletions .scripts/update-icon-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ const gitClient = (options={baseDir: srcSvgBasePath, binary: 'git'} ) => {
* @param {*} nextVersionType - The type of version that will be performed
* @param {*} preid - The prereleaese identifier if type is `pre*`
*/
const run = async (nextVersionType = 'none', preid='') => {
const output = [nextVersionType];

if (preid != '' )
output.push(preid)

const run = async (nextVersionType = null, preid='') => {
let git = gitClient();

await git.add(srcSvgBasePath);
const statusResults = await git.status([srcSvgBasePath]);

const { created, deleted, modified, renamed } = statusResults;

if ( nextVersionType == 'none' ) {
if ( nextVersionType === null ) {
if ( deleted.length > 0 || renamed.length > 0) {
nextVersionType = 'major';
} else if (modified.length > 0 || created.length > 0 ) {
Expand All @@ -44,6 +39,11 @@ const run = async (nextVersionType = 'none', preid='') => {
}

try {
if (nextVersionType === null) {
console.error('Version has not been set please check raw logs to resolve issue');
process.exit();
}

git = git.cwd(process.cwd())

await git.stash(['save', '--include-untracked']);
Expand All @@ -65,11 +65,15 @@ const run = async (nextVersionType = 'none', preid='') => {
await git.commit(`ci(icons): v${iconPkgVersion}, ${msg}`)
await git.tag([`@pine-ds/icons@${iconPkgVersion}`, '-a', '-m', msg]);

process.stdout.write(output.join(','));
const output = [nextVersionType];
if (preid != '' )
output.push(preid)

console.log(output.join(','));
}
catch (e) {
console.error(`Error occurred: ${e}`);
await git.stash(['drop']); // Delete the stash created in the Run process;
// await git.stash(['drop']); // Delete the stash created in the Run process;
}
}

Expand All @@ -96,7 +100,6 @@ const getNextVersion = async (nextVersionType, preid) => {

}
catch (err) {
await git.stash(['drop']); // Delete the stash created in the Run process;
throw Error(`An Error occurred during Versioning: ${err.stderr.toString()}`);
}
}
Expand All @@ -122,13 +125,13 @@ const updateChangelogFile = async (iconPkgVersion) => {

let [,,versionType, preVersionId] = process.argv;

if ((versionType !== undefined && versionType.startsWith('pre')) && (preVersionId === undefined || preVersionId === '' )) {
if ((versionType?.startsWith('pre')) && (preVersionId === '' )) {
throw Error('When using a pre version type, you must include a preVersionId e.g alpha, beta, rc, etc')
}
else if (versionType.startsWith('pre') == false) {
preVersionId = undefined
}

run(versionType, preVersionId);


if (versionType !== '') {
run(versionType, preVersionId);
}
else {
run();
}

0 comments on commit 84fa0b9

Please sign in to comment.