From ad3f96061081030300dcaa44430dc31d938c8615 Mon Sep 17 00:00:00 2001 From: John Wilger Date: Sun, 18 Feb 2024 11:14:55 -0800 Subject: [PATCH] Update dev and CI tooling --- .github/workflows/elixir.yml | 8 +++-- .github/workflows/release.yml | 46 ++++++++++++++++++++++++++++ integrate.sh | 56 +++++++++++++++++++++++++++++++++++ pre-commit-sample | 23 ++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 integrate.sh create mode 100755 pre-commit-sample diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index f951429..c913570 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -5,6 +5,8 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + merge_group: + types: [checks_requested] permissions: contents: read @@ -23,8 +25,8 @@ jobs: - name: Set up Elixir uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 with: - elixir-version: '1.15.2' # [Required] Define the Elixir version - otp-version: '26.0' # [Required] Define the Erlang/OTP version + elixir-version: '1.16.0' # [Required] Define the Elixir version + otp-version: '26.2' # [Required] Define the Erlang/OTP version - name: Restore dependencies cache uses: actions/cache@v3 with: @@ -40,4 +42,6 @@ jobs: - name: Install dependencies run: mix deps.get - name: Run tests + run: mix test + - name: Run Quality Checks run: mix check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d294628 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: Publish Package +on: + release: + types: [published] + +env: + OPENAI_API_KEY: afakekeyneededfortests + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Elixir + uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 + with: + elixir-version: '1.16.0' # [Required] Define the Elixir version + otp-version: '26.2' # [Required] Define the Erlang/OTP version + - name: Restore dependencies cache + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix- + - name: Restore _build cache + uses: actions/cache@v3 + with: + path: _build + key: ${{ runner.os }}-build-${{ hashFiles('**/*.ex') }} + restore-keys: ${{ runner.os }}-build- + - name: Install dependencies + run: mix deps.get + - name: Check version + run: | + MIX_VERSION=$(grep 'version:' mix.exs | cut -d '"' -f2) + TAG_VERSION=${GITHUB_REF/refs\/tags\/v/} + if [ "$MIX_VERSION" != "$TAG_VERSION" ]; then + echo "Tag version ($TAG_VERSION) does not match mix.exs version ($MIX_VERSION)" + exit 1 + fi + - name: Publish to Hex + uses: synchronal/hex-publish-action@v3 + with: + name: gpt_agent + key: ${{ secrets.HEX_API_KEY }} + tag-release: false diff --git a/integrate.sh b/integrate.sh new file mode 100755 index 0000000..7d6059a --- /dev/null +++ b/integrate.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env sh + +# This script is used to integrate your local changes with the remote +# repository. See the documentation in the pre-commit-sample file for +# information on what we check prior to committing and pushing your changes. +# This script is intended as a convenient one-liner to commit your changes, push +# them to the remote repository, and watch the GitHub Actions workflow run in +# your terminal to ensure that the build is successful. + +set -e + +if [ ! -e ./.git/hooks/pre-commit ]; then + ln -s ../../pre-commit-sample ./.git/hooks/pre-commit +else + if [ "$(readlink -f ./.git/hooks/pre-commit)" != "$(readlink -f ./pre-commit-sample)" ]; then + echo "\n\n" + echo "\e[1;31m" + echo "**********************************************************************" + echo "* Error: pre-commit hook conflict *" + echo "* *" + echo "* You have an existing pre-commit hook at ./.git/hooks/pre-commit, so *" + echo "* we will not install the hook required by this script. Please *" + echo "* review the hook in ./pre-commit-sample and consider removing your *" + echo "* current pre-commit hook. *" + echo "**********************************************************************" + echo "\e[0m" + echo "\n\n" + exit 1 + fi +fi + +git add -N . +git add -p +git commit --no-verify -m "TEMPORARY UNTESTED COMMIT\n\nIf you are seeing this in the commit log, it probably means that the integrate.sh script failed. You should do a soft reset to the commit prior to this commit." + +if git diff --exit-code; then + echo "No uncommitted changes to stash" + changes_stashed=0 +else + echo "Stashing uncommitted changes" + changes_stashed=1 + git restore --staged . + git stash push --include-untracked -m "Temporary stash for uncommitted changes" +fi + +git pull --rebase +git reset --soft HEAD^ +git status +mix clean +git commit +git push +if [ $changes_stashed -eq 1 ]; then + git stash pop +fi +sleep 2 +gh run watch --exit-status \ No newline at end of file diff --git a/pre-commit-sample b/pre-commit-sample new file mode 100755 index 0000000..47c900e --- /dev/null +++ b/pre-commit-sample @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +exec 1>&2 + +if ! git diff --exit-code; then + echo "\n\n" + echo "\e[1;31m" + echo "**********************************************************************" + echo "* Error: There are unstaged changes! *" + echo "* *" + echo "* You must run your pre-commit tests against the same code that will *" + echo "* actually be commited, and the presence of unstaged changes will *" + echo "* prevent that. We recommend using the integrate.sh script in this *" + echo "* repository to take care of automatically stashing these changes *" + echo "* for you. *" + echo "**********************************************************************" + echo "\e[0m" + echo "\n\n" + exit 1 +fi + +mix check && \ +mix test \ No newline at end of file