Skip to content

Commit

Permalink
Rework by importing changes from template-repo (#6)
Browse files Browse the repository at this point in the history
- Add `credo`
- Add `dependabot`
- Add VSCode devcontainer
- Add `husky`
- Add `prettier`
- Add `prettier-plugin-eex`
- Add `markdownlint-cli`
- Put `test` and `lint` in same workflow
- Add `run` file to test, lint and format
- Add `Dockerfile` containing project environement
- Be able to use `git` correctly with docker `dev` target
- Add documentations
- Bump `elixir`
- Bump `npm`
  • Loading branch information
aifrak authored Jun 30, 2021
1 parent dea87e8 commit 4a208e2
Show file tree
Hide file tree
Showing 50 changed files with 1,825 additions and 579 deletions.
44 changes: 44 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
%{
configs: [
%{
name: "default",
files: %{
included: ["lib/", "test/", "mix.exs", ".credo.exs", ".formatter.exs"],
excluded: []
},
strict: true,
checks: [
{Credo.Check.Design.AliasUsage, []},
# Avoid vscode-elixir-credo showing warnings wherease credo excludes ".exs" files.
# see: https://github.com/rrrene/credo/blob/master/lib/credo/check/readability/module_doc.ex
{Credo.Check.Readability.MaxLineLength, [max_length: 98]},
{Credo.Check.Readability.ModuleDoc, [files: %{excluded: ["**/*.exs"]}]},
{Credo.Check.Warning.MixEnv, [files: %{excluded: ["mix.exs"]}]},

# Controversial and experimental checks
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Readability.AliasAs, []},
{Credo.Check.Readability.BlockPipe, []},
{Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, [files: %{excluded: ["mix.exs"]}]},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Refactor.ABCSize, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.UnsafeToAtom, []}
]
}
]
}
50 changes: 39 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
{
"name": "Existing Docker Compose (Extend)",
"dockerComposeFile": ["../docker-compose.yml", "../docker-compose.dev.yml"],
"name": "template-elixir",
"dockerComposeFile": [
"../docker-compose.yml",
"../docker-compose.dev.yml",
"docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/app",
"settings": {
"shellformat.path": "/usr/local/bin/shfmt"
},
"extensions": [
// Settings
// Elixir
"jakebecker.elixir-ls",
"pantajoe.vscode-elixir-credo",

// EditorConfig
"editorconfig.editorconfig",

// Github Actions
"cschleiden.vscode-github-actions",

// Docker
"ms-azuretools.vscode-docker",

// Dockerfile
"exiasr.hadolint",

// Shell
"foxundermoon.shell-format",
"timonwong.shellcheck",

// Markdown
"davidanson.vscode-markdownlint",
"yzhang.markdown-all-in-one",

// Format
"esbenp.prettier-vscode",
// YAML
"redhat.vscode-yaml",

// Spelling
"streetsidesoftware.code-spell-checker",
// Gitignore
"codezombiech.gitignore",

// Elixir
"jakebecker.elixir-ls",
// Formatters
"esbenp.prettier-vscode",

// Dockerfile
"exiasr.hadolint"
// Comments
"stackbreak.comment-divider",

// Spelling
"streetsidesoftware.code-spell-checker"
]
}
13 changes: 13 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.9"

services:
app:
build:
target: vscode
volumes:
- vscode:/home/app-user/.vscode-server/extensions
- vscode-insiders:/home/app-user/.vscode-server-insiders/extensions

volumes:
vscode:
vscode-insiders:
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# VSCode
.history/

# NodeJS
node_modules/

# Elixir
_build/
cover/
deps/
doc/
.fetch/
erl_crash.dump
*.ez
*.beam
/config/*.secret.exs
.elixir_ls/
14 changes: 10 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ quote_type = auto
[{*.ex,*.exs}]
max_line_length = 98

[{*.html.eex,*.html.leex}]
max_line_length = 120

[{run,pre-commit,*.sh}]
binary_next_line = true
switch_case_indent = true

[{Dockerfile*,*.dockerfile}]
binary_next_line = true

[{*.md,*.markdown}]
trim_trailing_whitespace = false

[{Makefile,**.mk}]
indent_style = tab
indent_size = tab
5 changes: 5 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter,.credo}.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 98
]
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2

# By default, Dependabot checks for new versions on Monday at 05:00 UTC.
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates#scheduleday

updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: "node"
update-types: ["version-update:semver-major"]

- package-ecosystem: "mix"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
19 changes: 19 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Dependabot auto merge

# Check Dependabot every Monday at 05:30 UTC (30 min after Dependabot)
on:
schedule:
- cron: "30 5 * * MON"

jobs:
auto-merge:
runs-on: ubuntu-20.04
steps:
- name: Dependabot auto merge
uses: PabioHQ/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
auto-label: true
approve: true
merge-minor: true
merge-patch: true
39 changes: 39 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create release

on:
workflow_dispatch:
inputs:
tag-version:
description: "Version (format: x.y.z)"
required: true

jobs:
create-release:
name: Create release
runs-on: ubuntu-20.04

steps:
- name: Checkout code
uses: actions/[email protected]

- name: Built tag
id: build-tag
run: |
TAG_VERSION="${{ github.event.inputs.tag-version }}"
BUILT_TAG="v${TAG_VERSION}"
echo "::set-output name=tag::${BUILT_TAG}"
- name: Create tag
uses: tvdias/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.build-tag.outputs.tag }}

- name: Create release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.build-tag.outputs.tag }}
draft: true
prerelease: false
40 changes: 0 additions & 40 deletions .github/workflows/dockerfile-lint.yml

This file was deleted.

38 changes: 0 additions & 38 deletions .github/workflows/markdown-lint.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests

on: [pull_request, push]

jobs:
tests:
name: Tests
runs-on: ubuntu-20.04

env:
IMAGE_TARGET: base
IMAGE_TAG: aifrak/template-elixir:latest
CACHE_OLD: /tmp/.buildx-cache
CACHE_NEW: /tmp/.buildx-cache-new

steps:
- name: Checkout
uses: actions/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build image and cache
uses: docker/[email protected]
with:
load: true
target: ${{ env.IMAGE_TARGET }}
tags: ${{ env.IMAGE_TAG }}
cache-from: type=local,src=${{ env.CACHE_OLD }}
cache-to: type=local,dest=${{ env.CACHE_NEW }}

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf ${{ env.CACHE_OLD }}
mv ${{ env.CACHE_NEW }} ${{ env.CACHE_OLD }}
- name: Test
run: ./run dc:run test

- name: Lint
run: ./run dc:run lint
Loading

0 comments on commit 4a208e2

Please sign in to comment.