Skip to content

Commit 63e93fd

Browse files
author
David Staehler
committed
Setup CI (#1)
* Create private-elixir-library.yml * Styling fixes * Update deps * Fix tests * Bump versions * Remove test file
1 parent 8bd00ab commit 63e93fd

File tree

8 files changed

+312
-60
lines changed

8 files changed

+312
-60
lines changed
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
on: push
2+
3+
name: Privately published Elixir Library
4+
5+
env:
6+
ELIXIR_VERSION: "1.9"
7+
OTP_VERSION: "22.2"
8+
9+
jobs:
10+
deps:
11+
runs-on: ubuntu-latest
12+
env:
13+
NARRATIVE_HEX_ORG_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
14+
MIX_ENV: test
15+
steps:
16+
- name: Checking out project
17+
uses: actions/checkout@v2
18+
- name: "Setting up Elixir"
19+
uses: actions/setup-elixir@v1
20+
with:
21+
otp-version: ${{ env.OTP_VERSION }}
22+
elixir-version: ${{ env.ELIXIR_VERSION }}
23+
- name: Signing into narrativeapp organisation on hex
24+
run: mix hex.organization auth narrativeapp --key $NARRATIVE_HEX_ORG_API_KEY
25+
- name: Downloading dependency cache
26+
uses: actions/cache@v2
27+
with:
28+
path: deps
29+
key: ${{ runner.os }}-deps
30+
- run: mix deps.get
31+
- name: Uploading dependencies for other jobs
32+
uses: actions/upload-artifact@v2
33+
with:
34+
name: deps
35+
path: deps/
36+
37+
build:
38+
runs-on: ubuntu-latest
39+
needs: ["deps"]
40+
env:
41+
MIX_ENV: test
42+
steps:
43+
- name: Checking out project
44+
uses: actions/checkout@v2
45+
- name: "Setting up Elixir"
46+
uses: actions/setup-elixir@v1
47+
with:
48+
otp-version: ${{ env.OTP_VERSION }}
49+
elixir-version: ${{ env.ELIXIR_VERSION }}
50+
- name: Downloading dependencies
51+
uses: actions/download-artifact@v2
52+
with:
53+
name: deps
54+
path: deps/
55+
- name: Downloading build artifact cache
56+
uses: actions/cache@v2
57+
with:
58+
path: _build
59+
key: ${{ runner.os }}-build
60+
- name: Run `mix compile`
61+
run: mix compile
62+
- name: Uploading build artifacts for other jobs
63+
uses: actions/upload-artifact@v2
64+
with:
65+
name: build
66+
path: _build/
67+
68+
credo:
69+
runs-on: ubuntu-latest
70+
needs: ["deps", "build"]
71+
env:
72+
MIX_ENV: test
73+
steps:
74+
- name: Checking out project
75+
uses: actions/checkout@v2
76+
- name: "Setting up Elixir"
77+
uses: actions/setup-elixir@v1
78+
with:
79+
otp-version: ${{ env.OTP_VERSION }}
80+
elixir-version: ${{ env.ELIXIR_VERSION }}
81+
- name: Downloading dependencies
82+
uses: actions/download-artifact@v2
83+
with:
84+
name: deps
85+
path: deps/
86+
- name: Downloading build artifacts
87+
uses: actions/download-artifact@v2
88+
with:
89+
name: build
90+
path: _build/
91+
- run: mix credo --strict
92+
93+
formatter:
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Checking out project
97+
uses: actions/checkout@v2
98+
- name: "Setting up Elixir"
99+
uses: actions/setup-elixir@v1
100+
with:
101+
otp-version: ${{ env.OTP_VERSION }}
102+
elixir-version: ${{ env.ELIXIR_VERSION }}
103+
- run: mix format --check-formatted
104+
105+
audit:
106+
runs-on: ubuntu-latest
107+
needs: ["deps"]
108+
env:
109+
NARRATIVE_HEX_ORG_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
110+
MIX_ENV: test
111+
steps:
112+
- name: Checking out project
113+
uses: actions/checkout@v2
114+
- name: "Setting up Elixir"
115+
uses: actions/setup-elixir@v1
116+
with:
117+
otp-version: ${{ env.OTP_VERSION }}
118+
elixir-version: ${{ env.ELIXIR_VERSION }}
119+
- run: mix hex.organization auth narrativeapp --key $NARRATIVE_HEX_ORG_API_KEY
120+
- name: Downloading dependencies
121+
uses: actions/download-artifact@v2
122+
with:
123+
name: deps
124+
path: deps/
125+
- run: mix hex.audit
126+
127+
test:
128+
runs-on: ubuntu-latest
129+
needs: ["deps", "build"]
130+
env:
131+
MIX_ENV: test
132+
steps:
133+
- name: Checking out project
134+
uses: actions/checkout@v2
135+
- name: "Setting up Elixir"
136+
uses: actions/setup-elixir@v1
137+
with:
138+
otp-version: ${{ env.OTP_VERSION }}
139+
elixir-version: ${{ env.ELIXIR_VERSION }}
140+
- name: Downloading dependencies
141+
uses: actions/download-artifact@v2
142+
with:
143+
name: deps
144+
path: deps/
145+
- name: Downloading build artifacts
146+
uses: actions/download-artifact@v2
147+
with:
148+
name: build
149+
path: _build/
150+
- run: mix test
151+
152+
release:
153+
runs-on: ubuntu-latest
154+
needs: ["deps", "test", "audit", "formatter", "credo"]
155+
if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
156+
env:
157+
HEX_API_KEY: ${{ secrets.NARRATIVE_HEX_ORG_API_KEY }}
158+
steps:
159+
- name: Checking out project
160+
uses: actions/checkout@v2
161+
- name: Checking the tag version
162+
id: tag-version
163+
run: VERSION=$(basename ${{ github.ref }}) ; echo "::set-output name=tag-version::${VERSION:1}"
164+
- name: Checking the app version
165+
id: app-version
166+
run: "VERSION=$(awk -F\\\" '/version: /{print $2}' mix.exs); echo \"::set-output name=app-version::${VERSION}\""
167+
- name: Verifying that the git tag and the version in mix.exs match
168+
run: test "xx${{ steps.tag-version.outputs.tag-version }}" = "xx${{ steps.app-version.outputs.app-version }}"
169+
- name: Checking the app name
170+
id: app-name
171+
run: 'echo "::set-output name=app-name::$(awk -F''[:,]'' ''/app: /{print $3}'' mix.exs)"'
172+
- name: "Setting up Elixir"
173+
uses: actions/setup-elixir@v1
174+
with:
175+
otp-version: ${{ env.OTP_VERSION }}
176+
elixir-version: ${{ env.ELIXIR_VERSION }}
177+
- name: Downloading dependencies
178+
uses: actions/download-artifact@v2
179+
with:
180+
name: deps
181+
path: deps/
182+
- name: Downloading build artifacts
183+
uses: actions/download-artifact@v2
184+
with:
185+
name: build
186+
path: _build/
187+
- name: Run mix hex.build
188+
run: mix hex.build -o ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
189+
- name: Uploading hex package as job artifact
190+
uses: actions/upload-artifact@v2
191+
with:
192+
name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
193+
path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
194+
- name: Run mix docs
195+
run: MIX_ENV=test mix docs && tar zcvf docs.tar.gz doc/
196+
- name: Uploading documentation as job artifact
197+
uses: actions/upload-artifact@v2
198+
with:
199+
name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz
200+
path: docs.tar.gz
201+
- name: Publishing hex package
202+
run: mix hex.publish --organization narrativeapp --yes
203+
- name: Creating new Github release
204+
id: create-release
205+
uses: actions/create-release@v1
206+
env:
207+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208+
with:
209+
tag_name: v${{ steps.app-version.outputs.app-version }}
210+
release_name: Release ${{ steps.app-name.outputs.app-name }} ${{ steps.app-version.outputs.app-version }}
211+
body: Autogenerated from tag push
212+
- name: Uploading hex package as release artifact
213+
id: upload-package
214+
uses: actions/upload-release-asset@v1
215+
env:
216+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
217+
with:
218+
upload_url: ${{ steps.create-release.outputs.upload_url }}
219+
asset_path: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
220+
asset_name: ${{ steps.app-name.outputs.app-name }}-${{ steps.app-version.outputs.app-version }}.tar
221+
asset_content_type: application/x-tar
222+
- name: Uploading documentation as release artifact
223+
id: upload-docs
224+
uses: actions/upload-release-asset@v1
225+
env:
226+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227+
with:
228+
upload_url: ${{ steps.create-release.outputs.upload_url }}
229+
asset_path: docs.tar.gz
230+
asset_name: ${{ steps.app-name.outputs.app-name }}-docs-${{ steps.app-version.outputs.app-version }}.tar.gz
231+
asset_content_type: application/gzip

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ mix_deploy-*.tar
2424

2525
/rel/templates/
2626
/bin/
27-
.elixir_ls
27+
.elixir_ls
28+
.env

lib/mix/tasks/deploy.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule Mix.Tasks.Deploy do
2+
@moduledoc false
23
# Directory under _build where module stores generated files
34
@output_dir "deploy"
45

@@ -222,12 +223,13 @@ defmodule Mix.Tasks.Deploy.Init do
222223
"""
223224
@shortdoc "Initialize template files"
224225
use Mix.Task
226+
alias Mix.Tasks.Deploy
225227

226228
@app :mix_deploy
227229

228230
@spec run(OptionParser.argv()) :: no_return
229231
def run(args) do
230-
cfg = Mix.Tasks.Deploy.parse_args(args)
232+
cfg = Deploy.parse_args(args)
231233

232234
template_dir = cfg[:template_dir]
233235
app_dir = Application.app_dir(@app, ["priv", "templates"])
@@ -249,6 +251,7 @@ defmodule Mix.Tasks.Deploy.Generate do
249251
@shortdoc "Create deploy scripts and files"
250252
use Mix.Task
251253

254+
alias Mix.Tasks.Deploy
252255
alias MixDeploy.Templates
253256

254257
def flags_dir(cfg) do
@@ -269,7 +272,7 @@ defmodule Mix.Tasks.Deploy.Generate do
269272

270273
@spec run(OptionParser.argv()) :: no_return
271274
def run(args) do
272-
cfg = Mix.Tasks.Deploy.parse_args(args)
275+
cfg = Deploy.parse_args(args)
273276
ext_name = cfg[:ext_name]
274277
output_dir = cfg[:output_dir]
275278

@@ -368,10 +371,12 @@ defmodule Mix.Tasks.Deploy.Local do
368371

369372
use Mix.Task
370373

374+
alias Mix.Tasks.Deploy
375+
371376
@spec run(OptionParser.argv()) :: no_return
372377
def run(args) do
373378
# IO.puts (inspect args)
374-
config = Mix.Tasks.Deploy.parse_args(args)
379+
config = Deploy.parse_args(args)
375380
deploy_release(config)
376381
end
377382

@@ -423,8 +428,10 @@ defmodule Mix.Tasks.Deploy.Local.Rollback do
423428

424429
use Mix.Task
425430

431+
alias Mix.Tasks.Deploy
432+
426433
def run(args) do
427-
cfg = Mix.Tasks.Deploy.parse_args(args)
434+
cfg = Deploy.parse_args(args)
428435

429436
dirs = cfg[:releases_path] |> File.ls!() |> Enum.sort() |> Enum.reverse()
430437

lib/mix_deploy/templates.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ defmodule MixDeploy.Templates do
99
@app :mix_deploy
1010

1111
@doc "Generate file from template"
12-
@spec write_template(Keyword.t, Path.t, String.t) :: :ok
12+
@spec write_template(Keyword.t(), Path.t(), String.t()) :: :ok
1313
def write_template(vars, target_path, template) do
1414
write_template(vars, target_path, template, template)
1515
end
1616

17-
@spec write_template(Keyword.t, Path.t, String.t, Path.t) :: :ok
17+
@spec write_template(Keyword.t(), Path.t(), String.t(), Path.t()) :: :ok
1818
def write_template(vars, target_path, template, filename) do
1919
target_file = Path.join(target_path, filename)
2020
:ok = File.mkdir_p(target_path)
@@ -24,19 +24,20 @@ defmodule MixDeploy.Templates do
2424
end
2525

2626
@doc "Evaluate template file with bindings"
27-
@spec template_file(String.t, Keyword.t) :: {:ok, String.t} | {:error, term}
27+
@spec template_file(String.t(), Keyword.t()) :: {:ok, String.t()} | {:error, term}
2828
def template_file(template_file, bindings \\ []) do
29-
{:ok, EEx.eval_file(template_file, bindings, [trim: true])}
29+
{:ok, EEx.eval_file(template_file, bindings, trim: true)}
3030
rescue
3131
e ->
3232
{:error, {:template, e}}
3333
end
3434

3535
@doc "Find template matching name and eval"
36-
@spec template_name(Path.t, Keyword.t) :: {:ok, String.t} | {:error, term}
36+
@spec template_name(Path.t(), Keyword.t()) :: {:ok, String.t()} | {:error, term}
3737
def template_name(name, vars \\ []) do
3838
template_file = "#{name}.eex"
3939
override_file = Path.join(vars[:template_dir], template_file)
40+
4041
if File.exists?(override_file) do
4142
template_file(override_file)
4243
else

0 commit comments

Comments
 (0)