Skip to content

Commit

Permalink
added release.mjs script and release.yml gh action (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
bverbeken authored Mar 17, 2023
1 parent c32dc0c commit d305fa2
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
63 changes: 63 additions & 0 deletions release.mjs
Original file line number Diff line number Diff line change
@@ -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
})
}
4 changes: 0 additions & 4 deletions releasing.md

This file was deleted.

0 comments on commit d305fa2

Please sign in to comment.