Skip to content

Commit

Permalink
Allow publishing to Hex (#43)
Browse files Browse the repository at this point in the history
* Set up for releasing to hex

* Test against earliest and latest versions

* Support earlier Elixir versions

* Add missing params to test

* We don't care about old formatters/dialyzer

* Try removing cache to address BEAM mismatch

* Allow running the checks locally

* Make sure Elixir/OTP versions don't share cache

* Update .github/workflows/publish-hex.yml

Co-authored-by: Jason Pollentier <802805+grossvogel@users.noreply.github.com>

* Older versions already checked in other workflows

This would have also caused the pubish command to be run twice

---------

Co-authored-by: Jason Pollentier <802805+grossvogel@users.noreply.github.com>
  • Loading branch information
estreeper and grossvogel authored May 3, 2024
1 parent 3c5cd24 commit d5137c7
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 10 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/publish-hex.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish to Hex

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-22.04
name: Publish to Hex
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
MIX_ENV: test
strategy:
matrix:
include:
- otp: "26"
elixir: "1.16"
steps:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Checkout code
uses: actions/checkout@v4

# We want to use the newest deps here, since library users will not be
# locked to our mix.lock versions
- name: Install dependencies
run: mix deps.unlock --all && mix deps.get

- name: Compile and fail on warnings
run: mix compile --warnings-as-errors

- name: Check formatting
run: mix format --check-formatted

- name: Check function specs with Dialyzer
run: mix dialyzer

- name: Run tests
run: mix test

- name: Publish to Hex
run: mix hex.publish --yes
15 changes: 10 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ jobs:
MIX_ENV: test
strategy:
matrix:
otp: ["26.2"]
elixir: ["1.16.2"]
include:
- otp: "24"
elixir: "1.12"
- otp: "26"
elixir: "1.16"
steps:
- name: Set up Elixir
uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -42,10 +45,10 @@ jobs:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
key: ${{ runner.os }}-mix-${{ env.cache-name }}-elixir-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
${{ runner.os }}-mix-
${{ runner.os }}-mix-${{ env.cache-name }}-elixir-${{ matrix.elixir }}-
${{ runner.os }}-mix-${{ matrix.elixir }}-
- name: Install dependencies
run: mix deps.get
Expand All @@ -54,6 +57,7 @@ jobs:
run: mix compile --warnings-as-errors

- name: Check formatting
if: matrix.elixir == '1.16' && matrix.otp == '26'
run: mix format --check-formatted

- name: Cache PLT files for Dialyzer
Expand All @@ -67,6 +71,7 @@ jobs:
plt-cache-
- name: Check function specs with Dialyzer
if: matrix.elixir == '1.16' && matrix.otp == '26'
run: mix dialyzer

- name: Run tests
Expand Down
19 changes: 16 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@ to get started. Copy `config/config.example-secret.exs` to

## Development Setup

1. Make sure you have Elixir 1.16+ installed
1. Make sure you have Elixir 1.12+ installed
1. Clone the repo
1. Run `mix deps.get`
1. Run `mix test`

You can run the same checks that are in the CI pipeline, which is run via GitHub Actions:

```
./presubmit.sh
```

For convenience we recommend using this as a pre-push hook:

```
cp presubmit.sh .git/hooks/pre-push
```

## Submitting Changes

1. Find or open an Issue related to the changes you're making
1. Fork the project
1. Create a new topic branch to contain your feature, change, or fix.
1. Make sure all the tests are still passing.
1. Make sure all the checks are still passing: the CI system runs these checks automatically
1. Implement your feature, change, or fix. Make sure to write tests, update and/or add documentation.
1. Push your topic branch up to your fork.
1. Open a Pull Request with a clear title and description.
1. Open a Pull Request with a clear title and description, and mention the related Issue(s)
5 changes: 4 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ defmodule ProdopsEx.MixProject do
def project do
[
app: :prodops_ex,
description: "An SDK for interacting with the ProdOps API",
license: "MIT",
version: "0.1.0",
elixir: "~> 1.16",
elixir: "~> 1.12",
deps: deps(),
compilers: [:yecc, :leex] ++ Mix.compilers(),
aliases: aliases(),

# Docs
name: "ProdopsEx",
source_url: "https://github.com/revelrylabs/prodops_ex",
homepage_url: "https://prodops.ai",
docs: [
main: "readme",
logo: "prodops-logo.png",
Expand Down
32 changes: 32 additions & 0 deletions presubmit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
echo "Running pre-push checks (skip with --no-verify)..."

interrupt() {
echo "\n"
echo "Trapped the INT signal, exiting..."
# https://tldp.org/LDP/abs/html/exitcodes.html
exit 130
}

print_skip_message() {
echo "\n"
echo "Checks failed, see above. You can skip them by running git push --no-verify."
}

trap interrupt INT
# Ensure the skip message is printed when the script exits
trap '[[ $? -ne 0 ]] && print_skip_message' EXIT

mix format --check-formatted
if [ $? -ne 0 ]; then
exit 1
fi

mix dialyzer
if [ $? -ne 0 ]; then
exit 1
fi

mix test
if [ $? -ne 0 ]; then
exit 1
fi
2 changes: 1 addition & 1 deletion test/prodops_ex/artifact_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule ProdopsEx.ArtifactTest do
describe "stream_refine_artifact/2" do
test "streams refinement of an artifact by submitting a request with the required parameters" do
config = [api_url: "https://api.example.com", api_key: "secret_key"]
params = %{artifact_id: 1, artifact_slug: "story"}
params = %{stream: true, artifact_id: 1, artifact_slug: "story", refine_prompt: "refine prompt"}
full_url = "#{config[:api_url]}/api/v1/artifact_types/story/artifacts/1/refine_stream"

response = {:ok, %{"status" => "ok", "response" => %{"message" => "Artifact stream refined successfully."}}}
Expand Down

0 comments on commit d5137c7

Please sign in to comment.