From d305fa2297c5f0bf4e98fba671f53cdd34a6ede6 Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Fri, 17 Mar 2023 16:13:59 +0100 Subject: [PATCH] added release.mjs script and release.yml gh action (#75) --- .github/workflows/release.yml | 34 +++++++++++++++++++ release.mjs | 63 +++++++++++++++++++++++++++++++++++ releasing.md | 4 --- 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 release.mjs delete mode 100644 releasing.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..92c3909 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +# Very important! +# Make sure that the github token has read AND WRITE access on github. +# 1. hit https://github.com/seatsio/[REPO]/settings/actions +# 2. under "Workflow permissions", make sure "Read and write permissions" is checked instead of the (default?) read only. +# + +name: Release +run-name: Release ${{ github.repository }} +on: + workflow_dispatch: + inputs: + versionToBump: + description: 'The version to bump. Major for incompatible API changes, minor for adding BC features' + required: true + type: choice + options: + - minor + - major +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: fregante/setup-git-user@v2 + - id: install-zx + run: npm i -g zx + - id: install-semver-tool + run: | + wget -O /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver + chmod +x /usr/local/bin/semver + - run: zx ./release.mjs -v $VERSION_TO_BUMP + env: + VERSION_TO_BUMP: ${{ inputs.versionToBump }} + GH_TOKEN: ${{ github.token }} diff --git a/release.mjs b/release.mjs new file mode 100755 index 0000000..062d6e8 --- /dev/null +++ b/release.mjs @@ -0,0 +1,63 @@ +#!/usr/bin/env zx + +/* +* Script to release the seats.io java lib. +* - changes the version number in README.md +* - changes the version number in build.gradle +* - creates the release in Gihub (using gh cli) +* +* +* Prerequisites: +* - zx installed (https://github.com/google/zx) +* - gh cli installed (https://cli.github.com/) +* - semver cli installed (https://github.com/fsaintjacques/semver-tool) +* +* Usage: +* zx ./release.mjs -v major/minor -n "release notes" +* */ + +// don't output the commands themselves +$.verbose = false + +const versionToBump = getVersionToBump() +const latestVersion = await fetchLatestReleasedVersionNumber() + +await pullLastVersion().then(release) + +function getVersionToBump() { + if (!argv.v || !(argv.v === 'minor' || argv.v === 'major')) { + throw new Error ("Please specify -v major/minor") + } + return argv.v +} + +function removeLeadingV(tagName) { + if (tagName.startsWith('v')) { + return tagName.substring(1) + } + return tagName +} + +async function fetchLatestReleasedVersionNumber() { + let result = await $`gh release view --json tagName` + let tagName = JSON.parse(result).tagName + return removeLeadingV(tagName) +} + +async function determineNextVersionNumber(previous) { + return (await $`semver bump ${versionToBump} ${previous}`).stdout.trim() +} + +async function pullLastVersion() { + await $`git checkout master` + await $`git pull origin master` +} + +async function release() { + const nextVersion = await determineNextVersionNumber(latestVersion) + const newTag = 'v' + nextVersion + return await $`gh release create ${newTag} --generate-notes`.catch(error => { + console.error('something went wrong while creating the release. Please revert the version change!') + throw error + }) +} diff --git a/releasing.md b/releasing.md deleted file mode 100644 index d7f16d2..0000000 --- a/releasing.md +++ /dev/null @@ -1,4 +0,0 @@ -*Note: this is internal documentation for the seats.io team* - -1) Add upgrade instructions to README.md when releasing a new major version -2) Create the release in GitHub