From d86b701aeca9f4b3e806717005d7c632d6c5a001 Mon Sep 17 00:00:00 2001 From: DeveloperC Date: Sat, 19 Oct 2024 12:48:51 +0100 Subject: [PATCH] ci: adding release binary publishing --- .cargo/config.toml | 14 +++++ .github/workflows/continuous-delivery.yml | 29 ++++++++++ Earthfile | 12 +++++ ci/install-github-cli.sh | 12 +++++ ci/release-artifacts.sh | 64 +++++++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .github/workflows/continuous-delivery.yml create mode 100755 ci/install-github-cli.sh create mode 100755 ci/release-artifacts.sh diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..d748b7e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,14 @@ +# From https://github.com/BurntSushi/ripgrep/blob/master/.cargo/config.toml + +# Do the same for MUSL targets. At the time of writing (2023-10-23), this is +# the default. But the plan is for the default to change to dynamic linking. +# The whole point of MUSL with respect to ripgrep is to create a fully +# statically linked executable. +# +# See: https://github.com/rust-lang/compiler-team/issues/422 +# See: https://github.com/rust-lang/compiler-team/issues/422#issuecomment-812135847 +[target.x86_64-unknown-linux-musl] +rustflags = [ + "-C", "target-feature=+crt-static", + "-C", "link-self-contained=yes", +] diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml new file mode 100644 index 0000000..d1a5ca3 --- /dev/null +++ b/.github/workflows/continuous-delivery.yml @@ -0,0 +1,29 @@ +name: Continuous Delivery (CD) + +on: + release: + types: [published] + +# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs +permissions: + contents: write + +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.8.12. + uses: earthly/actions-setup@v1 + with: + version: v0.8.12 + - name: Checkout code. + uses: actions/checkout@v4 + - 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. diff --git a/Earthfile b/Earthfile index c0e748d..8ab9e09 100644 --- a/Earthfile +++ b/Earthfile @@ -187,3 +187,15 @@ end-to-end-test: RUN pip3 install -r "end-to-end-tests/requirements.txt" COPY "+compile/target/" "target/" RUN ./ci/end-to-end-test.sh + + +release-artifacts: + FROM +rust-base + DO +COPY_CI_DATA + # Needed by the GitHub CLI. + RUN apk add --no-cache git + RUN ./ci/install-github-cli.sh + DO +COPY_METADATA + DO +COPY_SOURCECODE + ARG release + RUN --secret GH_TOKEN ./ci/release-artifacts.sh --release "${release}" diff --git a/ci/install-github-cli.sh b/ci/install-github-cli.sh new file mode 100755 index 0000000..142a0e0 --- /dev/null +++ b/ci/install-github-cli.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +set -o errexit +set -o xtrace + +github_cli_version="2.30.0" +target="gh_${github_cli_version}_linux_amd64" + +wget "https://github.com/cli/cli/releases/download/v${github_cli_version}/${target}.tar.gz" +tar -xzvf "${target}.tar.gz" +mv "${target}/bin/gh" "/usr/local/bin/" +rm -rf "${target:?}/" diff --git a/ci/release-artifacts.sh b/ci/release-artifacts.sh new file mode 100755 index 0000000..7ace550 --- /dev/null +++ b/ci/release-artifacts.sh @@ -0,0 +1,64 @@ +#!/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 ]\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 + +target=$(rustc -vV | sed -n 's|host: ||p') +cargo build --verbose --release +gzip --verbose --stdout "target/release/conventional_commits_next_version" >"${target}.gz" +gh release upload "${_arg_release}" "${target}.gz" +# ] <-- needed because of Argbash