diff --git a/.github/workflows/releasing.yml b/.github/workflows/releasing.yml new file mode 100644 index 0000000..21b36a3 --- /dev/null +++ b/.github/workflows/releasing.yml @@ -0,0 +1,20 @@ +name: Releasing +on: + push: + branches: [main] +permissions: + contents: write +jobs: + Releasing: + runs-on: ubuntu-latest + steps: + - name: Download Earthly v0.7.5. + run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.5/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" + - name: Checkout code. + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Releasing. + run: earthly --ci --secret GH_TOKEN +releasing + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by GitHub Actions. diff --git a/Earthfile b/Earthfile index 0acfe50..3f1cc27 100644 --- a/Earthfile +++ b/Earthfile @@ -175,3 +175,14 @@ unit-testing: DO +INSTALL_DEPENDENCIES DO +COPY_SOURCECODE RUN ./ci/unit-testing.sh + + +releasing: + FROM ubuntu + RUN apt-get update + RUN apt-get install wget git -y + RUN wget https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_linux_amd64.tar.gz + RUN tar -xzvf gh_2.29.0_linux_amd64.tar.gz + RUN cp ./gh_2.29.0_linux_amd64/bin/gh /bin/gh + DO +COPY_METADATA + RUN --secret GH_TOKEN ./ci/releasing.sh diff --git a/ci/releasing.sh b/ci/releasing.sh new file mode 100755 index 0000000..7623bf4 --- /dev/null +++ b/ci/releasing.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +set -o errexit +set -o xtrace + +# Get current version. +current_version=$(cat "VERSION") +# If the tag already exist then exit. +git tag -l | grep -q "^${current_version}$" && exit 0 +# Where to start generating the release description from. +base_commit=$(git rev-list --max-parents=0 HEAD) +# latest_tag=$(git tag --sort=committerdate | tail -1) +# latest_tag=$(git show ${_arg_from_reference}:VERSION) +description_from="${latest_tag:-${base_commit}}" +# Generate the release description. +release_description=$(git log --format="* %s" ${description_from}.. --no-merges) +# Create release and the tag. +gh release create "${current_version}"