Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
ci: uploading release artifacts
Browse files Browse the repository at this point in the history
Using the GitHub CLI to upload the release artifacts created by GoReleaser,
because the release creation etc if managed by release-please.

Closes #76

## Testing
```sh
gh release create testing --generate-notes
gh release delete testing --cleanup-tag --yes
```
  • Loading branch information
DeveloperC286 committed Dec 30, 2023
1 parent d50110a commit d28d624
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Continuous Delivery (CD)

# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
contents: write

on:
release:
types: [published]

env:
# Forcing Earthly to use colours, to make reading output easier.
FORCE_COLOR: 1

jobs:
release-artifacts:
name: Release artifacts.
runs-on: ubuntu-latest
steps:
- name: Download Earthly v0.7.17.
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.17/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Checkout code.
uses: actions/checkout@v3
- name: Release artifacts.
run: earthly --ci --secret GH_TOKEN +release-artifacts --release "${GITHUB_REF_NAME}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by GitHub Actions.
3 changes: 1 addition & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: 1

builds:
- id: starling-bank-technical-challenge
main: ./cmd/starling-bank-technical-challenge
- main: ./cmd/starling-bank-technical-challenge
env:
- CGO_ENABLED=0
goos:
Expand Down
18 changes: 18 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,21 @@ unit-test:
DO +INSTALL_DEPENDENCIES
DO +COPY_SOURCECODE
RUN ./ci/unit-test.sh


INSTALL_GITHUB_CLI:
COMMAND
ENV GITHUB_CLI_VERSION=2.30.0
RUN wget "https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}/gh_${GITHUB_CLI_VERSION}_linux_amd64.tar.gz"
RUN tar -xzvf "gh_${GITHUB_CLI_VERSION}_linux_amd64.tar.gz"
RUN cp "./gh_${GITHUB_CLI_VERSION}_linux_amd64/bin/gh" /bin/gh


release-artifacts:
FROM +ubuntu-base
RUN apt-get install git wget jq -y
DO +INSTALL_GITHUB_CLI
COPY +compile/dist ./dist
DO +COPY_METADATA
ARG release
RUN --secret GH_TOKEN ./ci/release-artifacts.sh --release "${release}"
73 changes: 73 additions & 0 deletions ci/release-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

# ARG_OPTIONAL_SINGLE([release],[],[],[])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.9.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate

die() {
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}

begins_with_short_option() {
local first_option all_short_options=''
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}

# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_release=""

print_help() {
printf 'Usage: %s [--release <arg>]\n' "$0"
}

parse_commandline() {
while test $# -gt 0; do
_key="$1"
case "$_key" in
--release)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_release="$2"
shift
;;
--release=*)
_arg_release="${_key##--release=}"
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}

parse_commandline "$@"

# OTHER STUFF GENERATED BY Argbash

### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
set -o errexit
set -o xtrace

for row in $(jq -c '.[]' "dist/artifacts.json"); do
name=$(echo "${row}" | jq -r '.name')
name_without_extension=$(echo "${row}" | jq -r '.extra.Binary')
path=$(echo "${row}" | jq -r '.path')
name_with_architecture=$(echo "${path}" | cut -d '/' -f 2)
tmp_path="/tmp/${name//$name_without_extension/$name_with_architecture}"

# Move with new name, upload then delete.
# As otherwise asset names clash.
mv "${path}" "${tmp_path}"
gh release upload "${_arg_release}" "${tmp_path}"
rm "${tmp_path}"
done
# ] <-- needed because of Argbash

0 comments on commit d28d624

Please sign in to comment.