Skip to content

Commit

Permalink
Update dev and CI tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilger committed Feb 18, 2024
1 parent 8fdb8a6 commit ad3f960
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
merge_group:
types: [checks_requested]

permissions:
contents: read
Expand All @@ -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:
Expand All @@ -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
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions integrate.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions pre-commit-sample
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ad3f960

Please sign in to comment.