Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
update workflow scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
leocov-dev committed Oct 23, 2022
1 parent 41c2623 commit 2a66855
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 95 deletions.
97 changes: 29 additions & 68 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,53 @@
name: ci

on:
push:
branches:
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
pull_request:

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-go@v2
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Format Test
go-version-file: './go.mod'
cache: true

- name: Check Go Format
run: make fmtcheck

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-go@v2
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Tests
go-version-file: './go.mod'
cache: true

- name: Run Tests
run: make test

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Branch Info
id: branch_info
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-go@v2
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Deps
go-version-file: './go.mod'
cache: true

- name: Install GOX
run: go install github.com/mitchellh/gox@latest
- name: Build
run: env RELEASE_TAG=${{ steps.branch_info.outputs.TAG }} make release
- name: Build Files
run: ls ${{ github.workspace }}/dist
- uses: actions/cache@v2
with:
path: ${{ github.workspace }}/dist
key: build-go-${{ hashFiles('**/*.sha256') }}
restore-keys: |
build-go-

release:
needs:
- format
- test
- build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v2
with:
path: ${{ github.workspace }}/dist
key: build-go-${{ hashFiles('**/*.sha256') }}
restore-keys: |
build-go-
- name: List Files
run: ls ${{ github.workspace }}/dist
- name: Release
uses: softprops/action-gh-release@v1
with:
files: ${{ github.workspace }}/dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Multi-target Build
run: make release
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: release

on:
release:
types: [created]

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: "${{ github.workspace }}/go.mod"
cache: true

- name: Install GOX
run: go install github.com/mitchellh/gox@latest

- name: Multi-target Build
run: RELEASE_TAG=${GITHUB_REF#refs/tags/} make release

- name: List Files
run: ls ${{ github.workspace }}/dist

- name: Push Files
uses: softprops/action-gh-release@v1
with:
files: ${{ github.workspace }}/dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80 changes: 53 additions & 27 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ XC_ARCH=${XC_ARCH:-"arm arm64 amd64"}
XC_OS=${XC_OS:-"linux darwin windows"}
XC_EXCLUDE_OSARCH="!darwin/arm !windows/arm"

# Delete the old dir
echo
echo "==> Removing old directory..."
rm -rf bin/*
mkdir -p bin/
rm -rf dist/*
if [[ -d ./bin || -d ./dist ]]; then
echo
echo "==> Clearing Old Builds..."
rm -rf bin/*
rm -rf dist/*
fi

mkdir -p dist/

if ! command -v gox >/dev/null; then
Expand All @@ -51,42 +52,67 @@ echo
echo "==> Building..."
echo "ldflags: ${LD_FLAGS}"

BIN_NAME=${PWD##*/}
BUILD_PREFIX="${BIN_NAME}-"
BIN_NAME="tadpoles-backup"
BUILD_PREFIX="${BIN_NAME}"

gox \
-os="${XC_OS}" \
-arch="${XC_ARCH}" \
-osarch="${XC_EXCLUDE_OSARCH}" \
-ldflags "${LD_FLAGS}" \
-output "dist/${BUILD_PREFIX}{{.OS}}-{{.Arch}}" \
-output "dist/${BUILD_PREFIX}-{{.OS}}-{{.Arch}}" \
.

# Copy our OS/Arch to the bin/ directory
# only when not running in CI
DEV_PLATFORM="./dist/${BUILD_PREFIX}$(go env GOOS)-$(go env GOARCH)"
if [[ -f "${DEV_PLATFORM}" && -z "${CI}" ]]; then
mkdir -p bin/
echo
echo "==> Moving ${DEV_PLATFORM} to bin/"
echo "==> Copy ${DEV_PLATFORM} to bin/"
cp "${DEV_PLATFORM}" "./bin/${BIN_NAME}"
fi

# Packaging operations
# only if not a pull request
if [[ -z "${CI}" || "${TRAVIS_PULL_REQUEST}" == "false" ]]; then
echo
echo "==> Packaging..."
echo
for file in ./dist/*; do
echo "--> ${file}"

echo " calculate hash..."
sha256sum "./${file}" >"./${file}.sha256"
done

# Done!
echo
echo "==> Results:"
echo
ls -hl dist/*
if [[ -n "${CI}" ]]; then
echo
echo "==> Packaging..."
echo
for file in ./dist/*; do
echo "--> ${file}"

echo " calculate hash..."
sha256sum "./${file}" >"./${file}.sha256"

# IF there is a file extension, find and store it
if [[ ${file##*/} =~ \. ]]; then
ext="${file##*.}"
if [[ -n ${ext} ]]; then
ext=".${ext}"
fi
fi

build="./dist/${BUILD_PREFIX}${ext}"
sha="./dist/${BUILD_PREFIX}${ext}.sha256"

echo "build: ${build}"
echo "sha: ${sha}"

mv -f "${file}" "${build}"
mv -f "${file}.sha256" "${sha}"

if [[ -n $ext ]]; then
zip -j "${file%.*}" "${build}" "${sha}"
else
zip -j "${file}" "${build}" "${sha}"
fi

rm -f "${build}" "${sha}"
done

# Done!
echo
echo "==> Results:"
echo
ls -hl dist/*
fi

0 comments on commit 2a66855

Please sign in to comment.