diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..13062fc --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,44 @@ +name: Release +run-name: Release version ${{ github.event.inputs.version }} + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to release' + required: true + +permissions: + contents: write + +env: + BINARY_VERSION: ${{ github.event.inputs.version }} + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Configure git + run: | + git config --global user.name '${{ github.actor }}' + git config --global user.email '${{ github.actor }}@users.noreply.github.com' + - uses: actions/checkout@v4 + - name: Check version format + run: | + bin/check-version.pl + - uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + - name: Build + run: | + bin/build-binaries.sh + - name: Tag + run: | + git tag -a v${{ env.BINARY_VERSION }} -m "Release version ${{ env.BINARY_VERSION }}" + git push origin --tags + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: | + out/* + tag_name: ${{ env.BINARY_VERSION }} diff --git a/.gitignore b/.gitignore index eeeb7c2..f17211c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/out /test gen-elm-wrappers node_modules diff --git a/bin/build-binaries.sh b/bin/build-binaries.sh new file mode 100755 index 0000000..07db38e --- /dev/null +++ b/bin/build-binaries.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -euo pipefail + +: ${BINARY_VERSION?} + +list-binaries-to-build() { + # DAVE: extract this from suitable json file + echo darwin amd64 + echo darwin arm64 + echo linux amd64 + echo windows amd64 +} + +rm -rf out +mkdir out + +list-binaries-to-build | while read GOOS GOARCH ; do + case $GOOS in + windows) + BINARY_EXT=.exe + ;; + *) + BINARY_EXT='' + ;; + esac + BINARY_NAME="out/gen-elm-wrappers-$GOOS-$GOARCH-$BINARY_VERSION$BINARY_EXT" + export GOOS GOARCH BINARY_EXT BINARY_NAME + bin/build-binary.sh +done diff --git a/bin/build-binary.sh b/bin/build-binary.sh index 2076c36..bb21fe8 100755 --- a/bin/build-binary.sh +++ b/bin/build-binary.sh @@ -1,12 +1,10 @@ #!/bin/bash set -euo pipefail -if [[ -z "$BINARY_VERSION" ]] ; then - printf 'BINARY_VERSION not set\n' >&2 - exit 1 -fi +: ${BINARY_NAME?} +: ${BINARY_VERSION?} go build \ - -o gen-elm-wrappers \ + -o "$BINARY_NAME" \ -ldflags "-X main.Version=$BINARY_VERSION" \ github.com/dave4420/gen-elm-wrappers/src diff --git a/bin/check-version.pl b/bin/check-version.pl new file mode 100755 index 0000000..183db07 --- /dev/null +++ b/bin/check-version.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +use warnings; +use strict; + +local $_ = $ENV{BINARY_VERSION}; + +die "BINARY_VERSION is not set\n" unless defined; + +die "Version must be in the format X.Y.Z\n" unless /^\d+\.\d+\.\d+$/; + +print "Version is in the correct format\n"; diff --git a/bin/test.sh b/bin/test.sh index 4062746..c2b8d71 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -178,7 +178,7 @@ gen_elm_wrappers_json=' ' go test github.com/dave4420/gen-elm-wrappers/src -BINARY_VERSION='development-version' bin/build-binary.sh +BINARY_NAME=gen-elm-wrappers BINARY_VERSION='?.?.?' bin/build-binary.sh expect_success 'core only' "$elm_json_core_only" "$gen_elm_wrappers_json" diff --git a/src/main.go b/src/main.go index 5107110..8c12282 100644 --- a/src/main.go +++ b/src/main.go @@ -140,3 +140,24 @@ func main() { exitCode = 1 } } + +// DAVE: verify that the version number is not already in use +// DAVE: find out how to download a binary from an npm package +// DAVE: find out what architectures supported by go and node +// node: +// - os.type() +// - Returns the operating system name as returned by uname(3). +// For example, it returns 'Linux' on Linux, 'Darwin' on macOS, +// and 'Windows_NT' on Windows. +// https://linux.die.net/man/3/uname +// https://en.wikipedia.org/wiki/Uname#Examples +// - os.arch() +// - Possible values are 'arm', 'arm64', 'ia32', 'loong64', 'mips', +// 'mipsel', 'ppc', 'ppc64', 'riscv64', 's390', 's390x', and 'x64'. +// go: +// - $GOOS and $GOARCH +// - valid combinations listed at https://go.dev/doc/install/source#environment +// DAVE: get and save npm creds to 1password +// DAVE: install 1password in github actions and demo it fetching text from 1password +// DAVE: munge package.json to set version number and make it publishable +// DAVE: actually publish the package to npm