Skip to content

Commit

Permalink
Make release on Github
Browse files Browse the repository at this point in the history
  • Loading branch information
fileformat committed Aug 23, 2023
1 parent 5eaf377 commit 7296b72
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Version (semver)'
required: true
type: string

env:
VERSION: ${{inputs.version}}

jobs:
# Push image to GitHub Packages.
release:
name: Release

runs-on: ubuntu-22.04

steps:
# https://github.com/actions/checkout
- name: Checkout Project (main)
uses: actions/checkout@v3
with:
ref: main

# https://github.com/actions/setup-go
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.0'

- name: Build binaries
run: |
echo "Starting build"
./bin/build.sh "${VERSION}"
echo "Build complete"
- name: Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${VERSION}" \
--notes "Created by Github Action on $(date -u +%Y-%m-%dT%H:%M:%SZ)" \
./dist/which-dns
37 changes: 37 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#
# build which-dns
#

set -o errexit
set -o pipefail
set -o nounset

echo "INFO: build started at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

SCRIPT_HOME="$( cd "$( dirname "$0" )" && pwd )"
APP_HOME=$(realpath "$SCRIPT_HOME/..")

LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ)
VERSION=${1:-local@$(date -u +%Y-%m-%dT%H:%M:%SZ)}
GITHUB_SHA=${GITHUB_SHA:-$(git rev-parse --short HEAD)}

echo "PWD=$(pwd)"
echo "APP_HOME=${APP_HOME}"
echo "SCRIPT_HOME=${SCRIPT_HOME}"
echo "GITHUB_SHA=${GITHUB_SHA:-(not set)}"

echo "INFO: creating directory"
mkdir -p "${SCRIPT_HOME}/dist"

echo "INFO: building"
go build \
-a \
-trimpath \
-ldflags "-s -w -extldflags '-static' -X main.COMMIT=$GITHUB_SHA -X main.LASTMOD=$LASTMOD -X main.VERSION=$VERSION" \
-installsuffix cgo \
-tags netgo \
-o "${APP_HOME}/dist/which-dns" \
"${APP_HOME}/src"

echo "INFO: build complete at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
4 changes: 2 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# run locally
#
# NOTE: this may need to be run with 'sudo'
# NOTE: you may need to run this with 'sudo'
#

set -o errexit
Expand All @@ -14,6 +14,6 @@ LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ)

go run \
-ldflags "-X main.COMMIT=${COMMIT} -X main.LASTMOD=${LASTMOD}" \
. \
./src \
-local \
"-disclaimer=warnings go here"

0 comments on commit 7296b72

Please sign in to comment.