Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmlg authored Jan 22, 2025
0 parents commit 66a0071
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
108 changes: 108 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: test-and-release
on:
push:
branches:
- '+([0-9])?(.{+([0-9]),x}).x'
- main
- alpha
- beta
- next
- next-major
jobs:
tests:
name: Run tests (Elixir ${{matrix.elixir}}, OTP ${{matrix.otp}})

strategy:
matrix:
include:
- elixir: 1.13
otp: 24
lint: lint

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Restore deps and _build cache
uses: actions/cache@v2
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}
- name: Install dependencies
run: mix deps.get --only test

- name: Check source code format
run: mix format --check-formatted
if: ${{ matrix.lint }}

- name: Remove compiled application files
run: mix clean

- name: Compile dependencies
run: mix compile
if: ${{ !matrix.lint }}
env:
MIX_ENV: test

- name: Compile & lint dependencies
run: mix compile --warnings-as-errors
if: ${{ matrix.lint }}
env:
MIX_ENV: test

- name: Run tests
run: mix test

release:
name: semantic release
runs-on: ubuntu-latest
needs: [ tests ]
outputs:
version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: ⬇️ Checkout repo
uses: actions/checkout@v2

- name: 💊 Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '24'
elixir-version: '1.13.0'

- name: ⎔ Setup node
uses: actions/setup-node@v2
with:
node-version: 16

- name: 🚀 Release
uses: cycjimmy/semantic-release-action@v3
id: semantic
with:
semantic_version: 19
extra_plugins: |
@semantic-release/changelog
@semantic-release/exec
@semantic-release/git
env:
MIX_ENV: prod
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/mix.lock
/_build
/cover
/deps
/doc
/.elixir_ls
erl_crash.dump
*.ez
27 changes: 27 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repositoryUrl: https://github.com/gsmlg-dev/<app_otp_name>.git
branches:
- main
- next
- next-major
- {name: 'beta', prerelease: true}
- {name: 'alpha', prerelease: true}
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/changelog'
- - '@semantic-release/git'
- 'assets':
- 'CHANGELOG.md'
- 'mix.exs'
- 'README.md'
'message': 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
- '@semantic-release/github'
- - '@semantic-release/exec'
- 'prepareCmd' : |
echo ${nextRelease.version};
sed -i 's%@version "[0-9\.]\+"%@version "${nextRelease.version}"%' mix.exs;
mix deps.get;
sed -i 's%"~> [0-9\.]\+"},%"~> ${nextRelease.version}"},%' README.md;
'publishCmd' : |
echo pubhlish <app_otp_name> ${nextRelease.version};
mix hex.publish --yes
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changelog

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2022 Jonathan Gao

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Modify names in `replace_names.sh`
Then run `replace_names.sh`
Then delete this and `replace_names.sh`
---
# TemplateModuleName

[![release](https://github.com/gsmlg-dev/<app_otp_name>/actions/workflows/test-and-release.yml/badge.svg)](https://github.com/gsmlg-dev/<app_otp_name>/actions/workflows/test-and-release.yml)


See the [docs](https://hexdocs.pm/<app_otp_name>/) for more information.

## Install this package

Add deps in `mix.exs`

```elixir
{:<app_otp_name>, "~> 0.0.0"},
```



3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Config


2 changes: 2 additions & 0 deletions lib/template_module_name.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defmodule TemplateModuleName do
end
56 changes: 56 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
defmodule TemplateModuleName.Mixfile do
use Mix.Project

@source_url "https://github.com/gsmlg-dev/<app_otp_name>.git"
@version "0.0.0"

def project do
[
app: :<app_otp_name>,
version: @version,
elixir: "~> 1.7",
config_path: "config/config.exs",
deps: deps(),
name: "TemplateModuleName",
description: "Description of this package",
package: package(),
aliases: aliases(),
docs: [
extras: ["CHANGELOG.md"],
source_url: @source_url,
source_ref: "v#{@version}",
main: "TemplateModuleName",
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]
]
]
end

def application do
[
extra_applications: [:eex, :logger],
env: [csrf_token_reader: {Plug.CSRFProtection, :get_csrf_token_for, []}]
]
end

defp deps do
[
{:ex_doc, ">= 0.0.0", only: :prod, runtime: false}
]
end

defp package do
[
maintainers: ["Jonathan Gao"],
licenses: ["MIT"],
files: ~w(lib priv CHANGELOG.md LICENSE mix.exs README.md),
links: %{
Changelog: "https://hexdocs.pm/<app_otp_name>/changelog.html",
GitHub: @source_url
}
]
end

defp aliases do
[]
end
end
45 changes: 45 additions & 0 deletions replace_names.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash


replace() {

FROM=${1}
TO=${2}

PWD=$(pwd)
DIR=${3:-$PWD}

if [[ -z $FROM ]] || [[ -z $TO ]]
then
echo "replace [from] [to] [*path]"
exit 1
fi

#echo replace $FROM to $TO in $DIR

#echo "ag -l -Q $FROM $DIR"

for FILE in $(ag -l -Q "$FROM" "$DIR");
do
echo $FILE;
if [[ "$(uname -s)" == 'Darwin' ]]
then
sed -i '' "s%$FROM%$TO%g" $FILE;
else
sed -i "s%$FROM%$TO%g" $FILE;
fi
done

}


replace '<app_otp_name>' 'opt_name'

replace '<app_otp_name>' 'opt_name' '.releaserc.yaml'

replace 'TemplateModuleName' 'ModuleName'

mv 'lib/template_module_name.ex' 'lib/module_name.ex'

mv 'test/template_module_name_test.exs' 'test/module_name.exs'

10 changes: 10 additions & 0 deletions test/template_module_name_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule TemplateModuleNameTest do
use ExUnit.Case, async: true

import TemplateModuleName
doctest TemplateModuleName

test "Need add test" do
assert true == false
end
end
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()

0 comments on commit 66a0071

Please sign in to comment.