Skip to content

Commit

Permalink
Allow publishing binaries via GitHub (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
dave4420 authored Nov 21, 2023
1 parent 1dadc12 commit fd4d37b
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 6 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/out
/test
gen-elm-wrappers
node_modules
29 changes: 29 additions & 0 deletions bin/build-binaries.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 3 additions & 5 deletions bin/build-binary.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions bin/check-version.pl
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
21 changes: 21 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fd4d37b

Please sign in to comment.