Skip to content

Commit

Permalink
Configure CI and publish to hex. (#1)
Browse files Browse the repository at this point in the history
* Configure for publishing to our private org on hex.

* Add our github actions configuration and fix tests/credo.
  • Loading branch information
jimsynz authored Oct 1, 2020
1 parent edcf2b4 commit 806129a
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 51 deletions.
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
276 changes: 276 additions & 0 deletions .github/workflows/private-elixir-library.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
on: push

name: Privately published Elixir Library

env:
ELIXIR_VERSION: "1.9"
OTP_VERSION: "22.2"

jobs:
deps:
runs-on: ubuntu-latest
env:
NARRATIVE_HEX_ORG_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
MIX_ENV: test
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Signing into narrativeapp organisation on hex
run: mix hex.organization auth narrativeapp --key $NARRATIVE_HEX_ORG_API_KEY
- name: Downloading dependency cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-deps
- run: mix deps.get
- name: Uploading dependencies for other jobs
uses: actions/upload-artifact@v2
with:
name: deps
path: deps/

build:
runs-on: ubuntu-latest
needs: ["deps"]
env:
MIX_ENV: test
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Downloading dependencies
uses: actions/download-artifact@v2
with:
name: deps
path: deps/
- name: Downloading build artifact cache
uses: actions/cache@v2
with:
path: _build
key: ${{ runner.os }}-build
- name: Run `mix compile`
run: mix compile
- name: Uploading build artifacts for other jobs
uses: actions/upload-artifact@v2
with:
name: build
path: _build/

credo:
runs-on: ubuntu-latest
needs: ["deps", "build"]
env:
MIX_ENV: test
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Downloading dependencies
uses: actions/download-artifact@v2
with:
name: deps
path: deps/
- name: Downloading build artifacts
uses: actions/download-artifact@v2
with:
name: build
path: _build/
- run: mix credo --strict

formatter:
runs-on: ubuntu-latest
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- run: mix format --check-formatted

audit:
runs-on: ubuntu-latest
needs: ["deps"]
env:
NARRATIVE_HEX_ORG_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
MIX_ENV: test
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- run: mix hex.organization auth narrativeapp --key $NARRATIVE_HEX_ORG_API_KEY
- name: Downloading dependencies
uses: actions/download-artifact@v2
with:
name: deps
path: deps/
- run: mix hex.audit

test:
runs-on: ubuntu-latest
needs: ["deps", "build"]
env:
MIX_ENV: test
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Downloading dependencies
uses: actions/download-artifact@v2
with:
name: deps
path: deps/
- name: Downloading build artifacts
uses: actions/download-artifact@v2
with:
name: build
path: _build/
- run: mix test

is_releasable:
runs-on: ubuntu-latest
needs: ["deps", "test", "audit", "formatter", "credo"]
if: ${{ github.event_name == 'push' && !contains(github.ref, 'refs/tags/') }}
env:
HEX_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: Checking the app name
id: app-name
run: 'echo "::set-output name=app-name::$(awk -F''[:,]'' ''/app: /{print $3}'' mix.exs)"'
- name: Checking the app version
id: app-version
run: "VERSION=$(awk -F\\\" '/version: /{print $2}' mix.exs); echo \"::set-output name=app-version::${VERSION}\""
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Downloading dependencies
uses: actions/download-artifact@v2
with:
name: deps
path: deps/
- name: Downloading build artifacts
uses: actions/download-artifact@v2
with:
name: build
path: _build/
- name: Run mix hex.build
run: mix hex.build -o ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
- name: Uploading hex package as job artifact
uses: actions/upload-artifact@v2
with:
name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
- name: Run mix docs
run: MIX_ENV=test mix docs && tar zcvf docs.tar.gz doc/
- name: Uploading documentation as job artifact
uses: actions/upload-artifact@v2
with:
name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz
path: docs.tar.gz

release:
runs-on: ubuntu-latest
needs: ["deps", "test", "audit", "formatter", "credo"]
if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
env:
HEX_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
steps:
- name: Checking out project
uses: actions/checkout@v2
- name: Checking the tag version
id: tag-version
run: VERSION=$(basename ${{ github.ref }}) ; echo "::set-output name=tag-version::${VERSION:1}"
- name: Checking the app version
id: app-version
run: "VERSION=$(awk -F\\\" '/version: /{print $2}' mix.exs); echo \"::set-output name=app-version::${VERSION}\""
- name: Verifying that the git tag and the version in mix.exs match
run: test "xx${{ steps.tag-version.outputs.tag-version }}" = "xx${{ steps.app-version.outputs.app-version }}"
- name: Checking the app name
id: app-name
run: 'echo "::set-output name=app-name::$(awk -F''[:,]'' ''/app: /{print $3}'' mix.exs)"'
- name: "Setting up Elixir"
uses: actions/setup-elixir@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Downloading dependencies
uses: actions/download-artifact@v2
with:
name: deps
path: deps/
- name: Downloading build artifacts
uses: actions/download-artifact@v2
with:
name: build
path: _build/
- name: Run mix hex.build
run: mix hex.build -o ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
- name: Uploading hex package as job artifact
uses: actions/upload-artifact@v2
with:
name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
- name: Run mix docs
run: MIX_ENV=test mix docs && tar zcvf docs.tar.gz doc/
- name: Uploading documentation as job artifact
uses: actions/upload-artifact@v2
with:
name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz
path: docs.tar.gz
- name: Publishing hex package
run: mix hex.publish --organization narrativeapp --yes
- name: Creating new Github release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.app-version.outputs.app-version }}
release_name: Release ${{ steps.app-name.outputs.app-name }} ${{ steps.app-version.outputs.app-version }}
body: Autogenerated from tag push
- name: Uploading hex package as release artifact
id: upload-package
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
asset_name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
asset_content_type: application/x-tar
- name: Uploading documentation as release artifact
id: upload-docs
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: docs.tar.gz
asset_name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz
asset_content_type: application/gzip
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ use Mix.Config
config :ex_aws,
access_key_id: [System.get_env("AWS_ACCESS_KEY_ID"), :instance_role],
secret_access_key: [System.get_env("AWS_SECRET_ACCESS_KEY"), :instance_role],
s3: [region: "us-east-1"]
s3: [region: "us-east-1"]
Loading

0 comments on commit 806129a

Please sign in to comment.