Skip to content

Commit

Permalink
remove goreleaser. use bash scripts instead
Browse files Browse the repository at this point in the history
Signed-off-by: Sahin <[email protected]>
  • Loading branch information
thesayyn committed Feb 9, 2022
1 parent 1353a56 commit b4065d9
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 176 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: release

on:
# TODO: remove
workflow_dispatch:

jobs:
publish_artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.17.x'
- run: |
./hack/release_build.sh \
-a linux/amd64 -a linux/arm64 -a linux/armhf -a linux/armel -a linux/386 -a linux/s390x \
-a freebsd/amd64 -a freebsd/arm64 -a freebsd/armhf -a freebsd/armel -a freebsd/386 \
-a darwin/arm64 -a darwin/amd64
# TODO: enable this
# ./hack/release_sign.sh -S A135FAC32CC7DAE364F972CED3456C900C6869E1
- uses: actions/upload-artifact@v2
with:
path: ./release/*/*
37 changes: 0 additions & 37 deletions goreleaser.yaml

This file was deleted.

139 changes: 0 additions & 139 deletions hack/release.sh

This file was deleted.

169 changes: 169 additions & 0 deletions hack/release_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#!/bin/bash
# release.sh: configurable signed-artefact release script
# Copyright (C) 2016-2020 SUSE LLC
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

set -Eeuo pipefail
source "$(dirname "$BASH_SOURCE")/readlinkf.sh"

## --->
# Project-specific options and functions. In *theory* you shouldn't need to
# touch anything else in this script in order to use this elsewhere.
project="umoci"
root="$(readlinkf_posix "$(dirname "${BASH_SOURCE}")/..")"


# This function takes an output path as an argument, where the built
# (preferably static) binary should be placed.
function build_project() {
builddir="$(dirname "$1")"
shift
tmprootfs="$(mktemp -dt "$project-build.XXXXXX")"

for osarch in $@; do
IFS='/' read -ra OSARCH <<< "$osarch"
local OS=${OSARCH[0]}
local ARCH=${OSARCH[1]}
log "building for $OS/$ARCH"

set_cross_env $OS $ARCH
make -C "$root" BUILD_DIR="$tmprootfs" COMMIT_NO= "$project.static"
mv "$tmprootfs/$project.static" "$builddir/${project}_${OS}_$ARCH"
rm -rf "$tmprootfs"
done
}
# End of the easy-to-configure portion.
## <---

# Print usage information.
function usage() {
echo "usage: release_build.sh [-a <os/cross-arch>]... [-c <commit-ish>] [-H <hashcmd>]" >&2
echo " [-r <release-dir>] [-v <version>]" >&2
exit 1
}

# Log something to stderr.
function log() {
echo "[*]" "$@" >&2
}

# Log something to stderr and then exit with 0.
function bail() {
log "$@"
exit 0
}


function set_cross_env() {
GOOS="$1"
GOARCH="$2"
# it might be set from prev iterations
unset GOARM

case $2 in
armel)
GOARCH=arm
GOARM=6
;;
armhf)
GOARCH=arm
GOARM=7
;;
# since we already checked the archs we do not need to declare
# a case for them
esac
export GOOS GOARCH GOARM
}

# used to validate arch and os strings
supported_oses=(linux darwin freebsd)
supported_archs=(amd64 arm64 armhf armel 386 s390x)

function assert_os_arch_support() {
IFS='/' read -ra OSARCH <<< "$1"
if [[ ! "${supported_oses[*]}" =~ "${OSARCH[0]}" ]]; then
bail "unsupported os $1. expected one of: ${supported_oses[@]}"
fi
if [[ ! "${supported_archs[*]}" =~ "${OSARCH[1]}" ]]; then
bail "unsupported arch $1. expected one of: ${supported_archs[@]}"
fi
}



# When creating releases we need to build (ideally static) binaries, an archive
# of the current commit, and generate detached signatures for both.
keyid=""
version=""
commit="HEAD"
hashcmd="sha256sum"
# define os/arch targets to build for
declare -a osarch


while getopts "a:c:H:hr:v:" opt; do
case "$opt" in
a)
assert_os_arch_support "$OPTARG"
osarch+=($OPTARG)
;;
c)
commit="$OPTARG"
;;
H)
hashcmd="$OPTARG"
;;
h)
usage
;;
r)
releasedir="$OPTARG"
;;
v)
version="$OPTARG"
;;
:)
echo "Missing argument: -$OPTARG" >&2
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done


# Generate the defaults for version and so on *after* argument parsing and
# setup_project, to avoid calling get_version() needlessly.
version="${version:-$(<"$root/VERSION")}"
releasedir="${releasedir:-release/$version}"
hashcmd="${hashcmd:-sha256sum}"
# Suffixes of files to checksum/sign.
suffixes=(tar.xz ${supported_archs[@]})

log "creating $project release in '$releasedir'"
log " version: $version"
log " commit: $commit"
log " hash: $hashcmd"

# Make explicit what we're doing.
#set -x

# Make the release directory.
rm -rf "$releasedir" && mkdir -p "$releasedir"

# Build project.
build_project "$releasedir/$project" "${osarch[@]}"

# Generate new archive.
git archive --format=tar --prefix="$project-$version/" "$commit" | xz > "$releasedir/$project.tar.xz"

# Generate sha256 checksums for both.
(
cd "$releasedir"
"$hashcmd" $(tree -fai | grep ${suffixes[@]/#/-e } | tr '\n' ' ') > "$project.$hashcmd"
)
Loading

0 comments on commit b4065d9

Please sign in to comment.