diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ce1e12..5bfcdd4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,33 +1,139 @@ -image: elixir:latest - -cache: - key: "$CI_JOB_NAME" - paths: - - deps - - _build - - /root/.mix +stages: + - build + - test + - release variables: MIX_ENV: "test" + PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/" + HEX_HOME: "$CI_PROJECT_DIR/.hex" + MIX_HOME: "$CI_PROJECT_DIR/.mix" -before_script: - - mix local.hex --force - - mix local.rebar --force - - mix deps.get --only test +build: + image: elixir:latest + stage: build + cache: + key: "$CI_JOB_NAME" + paths: + - deps + - _build + - .hex + - .mix + script: + - mix local.hex --force + - mix local.rebar --force + - mix deps.get + - mix deps.compile + - mix git_ops.project_info -f dotenv > project_info.env + artifacts: + paths: + - _build/ + - deps/ + - .hex + - .mix + reports: + dotenv: project_info.env test: + image: elixir:latest + dependencies: + - build + stage: test script: - - mix test + - mix test credo: + image: elixir:latest + dependencies: + - build + stage: test script: - - mix credo --strict + - mix credo audit: + image: elixir:latest + dependencies: + - build + stage: test script: - mix hex.audit format: + image: elixir:latest + dependencies: + - build + stage: test script: - mix format --check-formatted +pages: + image: elixir:latest + dependencies: + - build + stage: release + script: + - mix docs -o public + artifacts: + paths: + - public + only: + - main + +git_ops: + image: elixir:latest + dependencies: + - build + stage: release + only: + refs: + - main + except: + variables: + - $CI_COMMIT_MESSAGE =~ /chore\:\ release version/ + script: + - | + export OLD_APP_VERSION=$APP_VERSION + mkdir -p artifacts + git config --global user.name "Gitlab Runner for ${GITLAB_USER_NAME}" + git config --global user.email "${GITLAB_USER_EMAIL}" + mix git_ops.release --yes || true + mix git_ops.project_info -f shell > artifacts/env + source artifacts/env + if [ "v${OLD_APP_VERSION}" != "v${APP_VERSION}" ]; then + mix hex.build -o "artifacts/${APP_NAME}-${APP_VERSION}.tar" + gzip "artifacts/${APP_NAME}-${APP_VERSION}.tar" + mix docs && tar zcvf "artifacts/${APP_NAME}-${APP_VERSION}-docs.tar.gz" doc/ + curl --header "JOB_TOKEN: ${CI_JOB_TOKEN}" --upload-file "artifacts/${APP_NAME}-${APP_VERSION}.tar.gz" "${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}.tar.gz" + curl --header "JOB_TOKEN: ${CI_JOB_TOKEN}" --upload-file "artifacts/${APP_NAME}-${APP_VERSION}-docs.tar.gz" "${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-docs.tar.gz" + git push "https://project_${CI_PROJECT_ID}_bot:${RELEASE_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git" "HEAD:${CI_COMMIT_REF_NAME}" "refs/tags/v${APP_VERSION}" + fi + artifacts: + paths: + - artifacts/* + +release-gitlab: + image: registry.gitlab.com/gitlab-org/release-cli:latest + dependencies: + - build + stage: release + only: + - tags + - /^v\d+\.\d+\.\d+(-\w+)?$/ + script: + - release-cli create \ + --name "Release ${APP_NAME} ${APP_VERSION}" \ + --description "./CHANGELOG.md" \ + --tag-name "v${APP_VERSION}" \ + --assets-link "{\"name\":\"${APP_NAME}-${APP_VERSION}.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}.tar.gz\"}" \ + --assets-link "{\"name\":\"${APP_NAME}-${APP_VERSION}-docs.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-docs.tar.gz\"}" + +release-hex: + image: elixir:latest + dependencies: + - build + stage: release + only: + - tags + - /^v\d+\.\d+\.\d+(-\w+)?$/ + script: + - mix hex.publish --yes diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..95f55be --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](Https://conventionalcommits.org) for commit guidelines. + + + +## [v1.1.1](https://gitlab.com/***PROJECT_PATH***/compare/v1.1.1...v1.1.1) (2021-12-08) + + + diff --git a/README.md b/README.md index 90da46c..2c2a172 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ by adding `ip` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:ip, "~> 1.0.0"} + {:ip, "~> 1.1.1"} ] end ``` diff --git a/config/config.exs b/config/config.exs index 25b3c21..cf21c23 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,30 +1,9 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config -# This configuration is loaded before any dependency and is restricted -# to this project. If another project depends on this project, this -# file won't be loaded nor affect the parent project. For this reason, -# if you want to provide default values for your application for -# 3rd-party users, it should be done in your "mix.exs" file. - -# You can configure your application as: -# -# config :ip, key: :value -# -# and access this configuration in your application as: -# -# Application.get_env(:ip, :key) -# -# You can also configure a 3rd-party app: -# -# config :logger, level: :info -# - -# It is also possible to import configuration files, relative to this -# directory. For example, you can emulate configuration per environment -# by uncommenting the line below and defining dev.exs, test.exs and such. -# Configuration from the imported file will override the ones defined -# here (which is why it is important to import them last). -# -# import_config "#{Mix.env}.exs" +config :git_ops, + mix_project: Mix.Project.get!(), + changelog_file: "CHANGELOG.md", + repository_url: "https://gitlab.com/***PROJECT_PATH***", + manage_mix_version?: true, + manage_readme_version: "README.md", + version_tag_prefix: "v" diff --git a/mix.exs b/mix.exs index 484fbcd..4008582 100644 --- a/mix.exs +++ b/mix.exs @@ -38,9 +38,10 @@ defmodule IP.Mixfile do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ex_doc, ">= 0.0.0", only: :dev}, - {:earmark, ">= 0.0.0", only: :dev}, - {:credo, "~> 1.0", only: ~w(dev test)a, runtime: false} + {:credo, "~> 1.0", only: ~w[dev test]a, runtime: false}, + {:earmark, ">= 0.0.0", only: ~w[dev test]a}, + {:ex_doc, ">= 0.0.0", only: ~w[dev test]a}, + {:git_ops, "~> 2.3", only: ~w[dev test]a, runtime: false} ] end end diff --git a/mix.lock b/mix.lock index da0cb00..94f70ad 100644 --- a/mix.lock +++ b/mix.lock @@ -6,6 +6,8 @@ "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"}, + "git_ops": {:hex, :git_ops, "2.4.5", "185a724dfde3745edd22f7571d59c47a835cf54ded67e9ccbc951920b7eec4c2", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e323a5b01ad53bc8c19c3a444be3e61ed7803ecd2e95530446ae9327d0143ecc"}, "inch_ex": {:hex, :inch_ex, "1.0.0", "18496a900ca4b7542a1ff1159e7f8be6c2012b74ca55ac70de5e805f14cdf939", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},