Skip to content

Commit

Permalink
use a Makefile for building, update the github actions accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed May 17, 2023
1 parent d430316 commit 9047bae
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 65 deletions.
44 changes: 21 additions & 23 deletions .github/workflows/go.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,40 @@ jobs:

build:
name: Build
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
outputs:
version_number: ${{ steps.version_number.outputs.version_number }}
steps:
- name: Install Linux packages
run: sudo apt update && sudo apt install -y --no-install-recommends libgtk-3-0 libgtk-3-dev libpango-1.0-0 libpango1.0-dev libpangocairo-1.0-0

- name: Set up Go 1.19
uses: actions/setup-go@v2
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get Gtk version and the environment
run: pkg-config --modversion gtk+-3.0;env

- name: Version Number
id: version_number
run: echo "version_number=$(make version_number)" >> $GITHUB_OUTPUT

- name: Caching build artifacts and modules
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-modules-${{ hashFiles('**/go.sum') }}

- name: Get dependencies
run: go get -v -t -d ./...
- name: Show Version
run: echo "Version ${{ steps.version_number.outputs.version_number }}"

- name: Build
run: go build -v -ldflags "-X main.version=$GITHUB_SHA" .

- name: Test
run: go test -v -timeout=30s ./...

run:
make deps test build

- name: 'Upload binary for linux_x86_64'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: hellocontest-binary
path: ./hellocontest
54 changes: 23 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,44 @@ on:
push:
tags:
- 'v*.*.*'

jobs:

build:
name: Build
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
outputs:
version_number: ${{ steps.version_number.outputs.version_number }}
package_name: ${{ steps.package_filename.outputs.package_filename }}
steps:
- id: version_number
run: echo "::set-output name=version_number::$(echo '${{github.ref}}' | sed -E 's#refs/tags/v##')"

- uses: actions/checkout@v2

- name: Install Linux packages
run: sudo apt update && sudo apt install -y --no-install-recommends libgtk-3-0 libgtk-3-dev libpango-1.0-0 libpango1.0-dev libpangocairo-1.0-0

- name: Set up Go 1.19
uses: actions/setup-go@v2
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
go-version: 1.19
fetch-depth: 0

- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: '1.20'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get Gtk version and the environment
run: |
pkg-config --modversion gtk+-3.0
env
- name: Caching build artifacts and modules
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-modules-${{ hashFiles('**/go.sum') }}

- name: Get dependencies
run: go get -v -t -d ./...
- name: Version Number
id: version_number
run: echo "version_number=$(make version_number)" >> $GITHUB_OUTPUT

- name: Show Version
run: echo "Version ${{ steps.version_number.outputs.version_number }}"

- name: Build
run: |
echo "Version ${{ steps.version_number.outputs.version_number }}"
go build -v -ldflags "-X main.version=${{ steps.version_number.outputs.version_number }}" .
- name: Test
run: go test -v -timeout=30s ./...
run: make deps test build

- name: Create package structure
run: |
Expand All @@ -58,13 +50,13 @@ jobs:
chmod +x ./.debpkg/usr/bin/hellocontest
- name: Create deb package
run: ./build-debpkg.sh ${{ steps.version_number.outputs.version_number }}
run: make debpkg

- id: package_filename
run: echo "::set-output name=package_filename::$(ls ./hellocontest*.deb | head -n 1)"
run: echo "package_filename=$(ls ./hellocontest*.deb | head -n 1)" >> $GITHUB_OUTPUT

- name: 'Upload package for linux_x86_64'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: hellocontest-package
path: ./hellocontest*.deb
Expand Down
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
VERSION_NUMBER=$(shell git describe --tags | sed -E 's#v##')
BINARY_NAME ?= hellocontest
INSTALL_DIR ?= /usr/local/bin

all: clean test build

clean:
go clean
rm -f ${BINARY_NAME}

deps:
go get -v -t -d ./...

generate:
go generate ./core/pb

version_number:
@echo ${VERSION_NUMBER}

test:
go test -v -timeout=30s ./...

build:
go build -v -ldflags "-X main.version=${VERSION_NUMBER}" -o ${BINARY_NAME}

run: build
./${BINARY_NAME}

install: clean build
cp ./${BINARY_NAME} ${INSTALL_DIR}/${BINARY_NAME}

uninstall:
rm ${INSTALL_DIR}/${BINARY_NAME}

checkout_latest:
git checkout `git tag --sort=committerdate | tail -1`

latest: clean checkout_latest test build

debpkg:
sed -i -E "s#!THE_VERSION!#${VERSION_NUMBER}#" ./.debpkg/DEBIAN/control
dpkg-deb --build ./.debpkg .
git restore ./.debpkg/DEBIAN/control
3 changes: 0 additions & 3 deletions build-debpkg.sh

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ftl/hellocontest

go 1.19
go 1.20

// replace github.com/ftl/cabrillo => ../cabrillo

Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/ftl/hellocontest/ui"
Expand All @@ -9,5 +10,10 @@ import (
var version = "development"

func main() {
if len(os.Args) == 2 && os.Args[1] == "version" {
fmt.Println(version)
os.Exit(0)
}

ui.Run(version, os.Args)
}
7 changes: 0 additions & 7 deletions update.sh

This file was deleted.

0 comments on commit 9047bae

Please sign in to comment.