-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b6d8a49
Showing
23 changed files
with
622 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
line_length: 120 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- Uncomment the line below for a link to a ticket, or ignore if there's no ticket --> | ||
<!-- This is a requirement of ticket: TICKET_LINK --> | ||
|
||
### What does this do on a high level and why? | ||
|
||
A quick sentence just so folks get an idea about the what, why, and how of these changes. | ||
|
||
### How was this verified? | ||
|
||
Fill this section if you had to do any manual testing or something out of the ordinary to test the changes in this PR. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
repository: | ||
# See https://developer.github.com/v3/repos/#edit for all available settings. | ||
|
||
# Either `true` to enable issues for this repository, `false` to disable them. | ||
has_issues: true | ||
|
||
# Either `true` to enable the wiki for this repository, `false` to disable it. | ||
has_wiki: false | ||
|
||
# Either `true` to enable downloads for this repository, `false` to disable them. | ||
has_downloads: true | ||
|
||
# Updates the default branch for this repository. | ||
default_branch: main | ||
|
||
# Either `true` to allow squash-merging pull requests, or `false` to prevent | ||
# squash-merging. | ||
allow_squash_merge: true | ||
|
||
# Either `true` to allow merging pull requests with a merge commit, or `false` | ||
# to prevent merging pull requests with merge commits. | ||
allow_merge_commit: false | ||
|
||
# Either `true` to allow rebase-merging pull requests, or `false` to prevent | ||
# rebase-merging. | ||
allow_rebase_merge: true | ||
|
||
# Either `true` to enable automatic deletion of branches on merge, or `false` | ||
# to disable. | ||
delete_branch_on_merge: true | ||
|
||
# Labels: define labels for Issues and Pull Requests | ||
labels: | ||
- name: "Ready for review" | ||
color: 0e8a16 | ||
- name: "WIP - Do not merge" | ||
color: e60205 | ||
|
||
branches: | ||
- name: main | ||
# https://developer.github.com/v3/repos/branches/#update-branch-protection | ||
# Branch Protection settings. Set to null to disable | ||
protection: | ||
# Required. Require at least one approving review on a pull request, before merging. Set to null to disable. | ||
required_pull_request_reviews: | ||
# The number of approvals required. (1-6) | ||
required_approving_review_count: 1 | ||
# Dismiss approved reviews automatically when a new commit is pushed. | ||
dismiss_stale_reviews: false | ||
# Blocks merge until code owners have reviewed. | ||
require_code_owner_reviews: false | ||
# Specify which users and teams can dismiss pull request reviews. Pass an empty dismissal_restrictions object to disable. User and team dismissal_restrictions are only available for organization-owned repositories. Omit this parameter for personal repositories. | ||
dismissal_restrictions: | ||
users: [] | ||
teams: [] | ||
# Required. Require status checks to pass before merging. Set to null to disable | ||
required_status_checks: | ||
# Required. Require branches to be up to date before merging. | ||
strict: true | ||
# Required. The list of status checks to require in order to merge into this branch | ||
contexts: [] | ||
# Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. | ||
enforce_admins: true | ||
# Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable. | ||
restrictions: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
cookie_cutter-*.tar | ||
|
||
# Gets created when CI setup is used locally. | ||
/ci/creds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.PHONY: help | ||
|
||
code-check: | ||
mix format --check-formatted | ||
mix lint.credo | ||
mix deps.unlock --check-unused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# CookieCutter | ||
|
||
**Important**: if you're creating a new Elixir library or service, make sure to read the Elixir project runbook in the [engineering repo](https://github.com/Shimmur/engineering/blob/main/runbooks/services/elixir_application.md). | ||
|
||
## Creating an Elixir project | ||
|
||
1. Use this repository as a GitHub template when creating a new repository. | ||
|
||
1. Run ./replace.sh my_app MyApp (with the right application name) to replace | ||
all instances of the name "cookie cutter" with the right names. For | ||
example, ./replace abc_handler ABCHandler. The replace.sh script will | ||
destroy itself once it runs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM quay.io/shimmur/elixir:1.11.2-otp22.2.3 | ||
|
||
ARG HEXPM_KEY | ||
ARG COVERALLS_REPO_TOKEN | ||
|
||
WORKDIR /otp/app | ||
|
||
RUN apk update && \ | ||
apk add --no-cache git openssh-client bash build-base ffmpeg && \ | ||
mix local.rebar --force && \ | ||
mix local.hex --force | ||
|
||
COPY . . | ||
|
||
RUN mix hex.organization auth community --key $HEXPM_KEY && mix deps.get | ||
|
||
RUN rm -rf _build | ||
|
||
CMD ./ci/scripts/ci-container.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3' | ||
|
||
services: | ||
tests: | ||
depends_on: [] | ||
build: | ||
context: .. | ||
dockerfile: ci/Dockerfile | ||
args: | ||
- HEXPM_KEY | ||
environment: [] | ||
links: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
resource_types: | ||
# Used for operating on Github pull requests | ||
- name: pull-request | ||
type: docker-image | ||
source: | ||
repository: teliaoss/github-pr-resource | ||
|
||
# Used for setting status on Github commits | ||
- name: github-status | ||
type: docker-image | ||
source: | ||
repository: dpb587/github-status-resource | ||
tag: master | ||
|
||
resources: | ||
# Used for fetching source and updating PR status | ||
- name: git-pr | ||
type: pull-request | ||
check_every: 1h | ||
webhook_token: b6fd0d78 | ||
icon: github-circle | ||
source: | ||
repository: Shimmur/elixir-lib-cookie-cutter | ||
access_token: ((github.token)) | ||
|
||
# Used for operating on <main> | ||
- name: git-main | ||
type: git | ||
check_every: 1h | ||
webhook_token: b6fd0d78 | ||
source: | ||
uri: https://github.com/Shimmur/elixir-lib-cookie-cutter.git | ||
branch: main | ||
username: ((github.username)) | ||
password: ((github.token)) | ||
|
||
# Used for setting status on commit | ||
- name: git-status | ||
type: github-status | ||
source: | ||
branch: main | ||
repository: Shimmur/elixir-lib-cookie-cutter | ||
access_token: ((github.token)) | ||
|
||
# Used as the base image for running tests; found in Shimmur/docker-images | ||
- name: build-base-image | ||
type: docker-image | ||
source: | ||
repository: quay.io/shimmur/concourse-dind | ||
tag: "24969e1" | ||
username: ((quayio.username)) | ||
password: ((quayio.password)) | ||
|
||
jobs: | ||
- name: test-pr | ||
public: true | ||
plan: | ||
# Get the build-base-image/dind image | ||
- get: build-base-image | ||
|
||
# Fetch the PR (allows latter steps to use for `inputs`) | ||
- get: git-pr | ||
trigger: true | ||
version: every | ||
|
||
# Mark the PR as "pending" in Github | ||
- put: git-pr | ||
params: | ||
path: git-pr | ||
status: pending | ||
|
||
# Run tests | ||
- task: run-tests | ||
image: build-base-image | ||
params: | ||
HEXPM_KEY: ((hexpm.key)) | ||
COVERALLS_REPO_TOKEN: ((coveralls.elixir_lib_cookie_cutter_repo_token)) | ||
privileged: true | ||
file: git-pr/ci/tasks/test-pr.yml | ||
on_failure: | ||
put: git-pr | ||
params: | ||
path: git-pr | ||
status: failure | ||
|
||
# Mark PR as "succeeded" in Github | ||
- put: git-pr | ||
params: | ||
path: git-pr | ||
status: success | ||
|
||
# Job will automatically run when `main` branch is updated | ||
- name: test-main | ||
public: true | ||
plan: | ||
- get: build-base-image | ||
- get: git-main | ||
trigger: true | ||
version: every | ||
- put: git-status | ||
params: { state: pending, commit: git-main } | ||
- task: run-tests | ||
image: build-base-image | ||
params: | ||
HEXPM_KEY: ((hexpm.key)) | ||
COVERALLS_REPO_TOKEN: ((coveralls.elixir_lib_cookie_cutter_repo_token)) | ||
privileged: true | ||
file: git-main/ci/tasks/test-main.yml | ||
on_failure: | ||
put: git-status | ||
params: { state: failure, commit: git-main } | ||
- put: git-status | ||
params: { state: success, commit: git-main } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
die() { | ||
echo $* >&2 | ||
exit 1 | ||
} | ||
|
||
banner() { | ||
echo | ||
echo "*** $* ***" | ||
echo | ||
} | ||
|
||
# Store creds we need in the build container | ||
./ci/scripts/pass-creds.sh || die "Can't pass credentials" | ||
|
||
# Wait on deps to start | ||
./ci/scripts/start-deps.sh || die "Can't start dependencies" | ||
|
||
banner "Building tests" | ||
|
||
# Run the tests and clean up | ||
docker-compose -f ci/docker-compose.yml build tests | ||
EXIT_CODE=$? | ||
|
||
if [[ $EXIT_CODE -eq 0 ]]; then | ||
banner "Running tests" | ||
docker-compose -f ci/docker-compose.yml run tests | ||
EXIT_CODE=$? | ||
echo "Exited with exit code '${EXIT_CODE}'" | ||
fi | ||
|
||
test $EXIT_CODE -eq 0 || banner "FAILED" | ||
|
||
banner "Cleaning up..." | ||
docker-compose -f ci/docker-compose.yml down | ||
|
||
# Make sure we fail if the tests run failed | ||
exit $EXIT_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh -e | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Script run as the CMD for the build container | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Source the creds we passed into the container | ||
source ./ci/creds | ||
|
||
# Run the tests | ||
export MIX_ENV=test | ||
make code-check | ||
|
||
if [ -z "$COVERALLS_REPO_TOKEN" ]; then | ||
echo "MISSING!!! COVERALLS_REPO_TOKEN is not set, can't report coverage!!!" | ||
mix test | ||
else | ||
./ci/scripts/cover.sh | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "${COVERALLS_REPO_TOKEN}" ]; then | ||
echo "Missing COVERALLS_REPO_TOKEN env var, please set in the CI system" | ||
exit 1 | ||
fi | ||
|
||
if [ -f /otp/app/.git/resource/head_sha ]; then | ||
# By now we have used git-pr to build a repo with one branch (master) | ||
# and all of the commits in it. To get to the meta-data for the PR we | ||
# need to do this ... (https://trits.ch/2UQz74j) | ||
export GIT_COMMIT="$(cat /otp/app/.git/resource/head_sha)" | ||
export GIT_COMMITTER="$(cat /otp/app/.git/resource/author)" | ||
export GIT_BRANCH="$(cat /otp/app/.git/resource/head_name)" | ||
export GIT_MESSAGE="$(cat /otp/app/.git/resource/message)" | ||
else | ||
export GIT_COMMIT="$(git rev-parse HEAD)" | ||
export GIT_COMMITTER="$(git log -1 $GIT_COMMIT --pretty=format:'%cN')" | ||
export GIT_BRANCH="$(git name-rev --name-only HEAD)" | ||
export GIT_MESSAGE="$(git log -1 $GIT_COMMIT --pretty=format:'%s')" | ||
fi | ||
|
||
echo "Uploading coverage report to coveralls.io ..." | ||
echo "- Commit: $GIT_COMMIT" | ||
echo "- Committer: $GIT_COMMITTER" | ||
echo "- Branch: $GIT_BRANCH" | ||
echo "- Message: $GIT_MESSAGE" | ||
|
||
export MIX_ENV=test | ||
mix coveralls.post \ | ||
--token "$COVERALLS_REPO_TOKEN" \ | ||
--sha "$GIT_COMMIT" \ | ||
--committer "$GIT_COMMITTER" \ | ||
--branch "$GIT_BRANCH" \ | ||
--message "$GIT_MESSAGE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Pass through credentials we need in the build container | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Space separated list of vars to pass through to the build | ||
EXPORTED_FIELDS="COVERALLS_REPO_TOKEN HEXPM_KEY" | ||
|
||
truncate -s0 ./ci/creds | ||
for field_name in $EXPORTED_FIELDS; do | ||
varname="$`echo $field_name`" | ||
eval value=$varname | ||
echo "export $field_name=$value" >> ./ci/creds | ||
done |
Oops, something went wrong.