From e28c0f934b969cfd524bbd408bfa8318af7f1f42 Mon Sep 17 00:00:00 2001 From: James Harton Date: Mon, 28 Dec 2020 19:15:13 +1300 Subject: [PATCH] chore: set up git_ops and auto-releasing --- .gitlab-ci.yml | 119 +++++++++++++++++++++++++++++++++++++++++----- CHANGELOG.md | 11 +++++ README.md | 2 +- config/config.exs | 8 ++++ mix.exs | 11 +++-- mix.lock | 2 + 6 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad72593..b18dda3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,42 +1,76 @@ -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 credo: + image: elixir:latest + dependencies: + - build stage: test script: - 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: - stage: deploy + image: elixir:latest + dependencies: + - build + stage: release script: - mix docs -o public artifacts: @@ -44,3 +78,62 @@ pages: - public only: - master + +git_ops: + image: elixir:latest + dependencies: + - build + stage: release + only: + refs: + - master + 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..14a9e45 --- /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. + + + +## [v0.3.0](https://gitlab.com/jimsy/mpl3115a2/compare/v0.3.0...v0.3.0) (2020-12-28) + + + diff --git a/README.md b/README.md index 120b072..9ee2be3 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ by adding `mpl3115a2` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:mpl3115a2, "~> 0.1.0"} + {:mpl3115a2, "~> 0.3.0"} ] end ``` diff --git a/config/config.exs b/config/config.exs index 1045bac..63d0b4d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -2,3 +2,11 @@ import Config config :mpl3115a2, devices: [%{bus: "i2c-1", address: 0x60}] + +config :git_ops, + mix_project: Mix.Project.get!(), + changelog_file: "CHANGELOG.md", + repository_url: "https://gitlab.com/jimsy/mpl3115a2", + manage_mix_version?: true, + manage_readme_version: "README.md", + version_tag_prefix: "v" diff --git a/mix.exs b/mix.exs index fb336c5..21ad70a 100644 --- a/mix.exs +++ b/mix.exs @@ -1,10 +1,12 @@ defmodule MPL3115A2.MixProject do use Mix.Project + @version "0.3.0" + def project do [ app: :mpl3115a2, - version: "0.3.0", + version: @version, elixir: "~> 1.9", start_permanent: Mix.env() == :prod, description: "Driver for the MPL3115A2 altimeter connected via I2C.", @@ -34,10 +36,11 @@ defmodule MPL3115A2.MixProject do defp deps do [ {:circuits_i2c, "~> 0.3", optional: true}, - {:credo, "~> 1.1", only: [:dev, :test], runtime: false}, - {:earmark, ">= 0.0.0", only: [:dev, :test]}, + {:credo, "~> 1.1", only: ~w[dev test]a, runtime: false}, + {:earmark, ">= 0.0.0", only: ~w[dev test]a}, {:elixir_ale, "~> 1.2", optional: true}, - {:ex_doc, ">= 0.0.0", only: [:dev, :test]}, + {:ex_doc, ">= 0.0.0", only: ~w[dev test]a}, + {:git_ops, "~> 2.3", only: ~w[dev test]a, runtime: false}, {:mimic, "~> 1.1", only: :test}, {:wafer, "~> 0.3"} ] diff --git a/mix.lock b/mix.lock index c04e01f..35e351d 100644 --- a/mix.lock +++ b/mix.lock @@ -7,6 +7,8 @@ "elixir_ale": {:hex, :elixir_ale, "1.2.1", "07ac2f17a0191b8bd3b0df6b526c7f699a3a4d690c9def573fcb5824eef24d98", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "bfb099137500a3b8c4a1750cf07f2d704897ef9feac3412064bf9edc7d74193c"}, "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"}, "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, + "git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"}, + "git_ops": {:hex, :git_ops, "2.3.0", "a77f91b810d874e1abf5f415f335959a2dfc3613cbcd28c7c05b97c666339fda", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "849bd53b7992963b3fdfebcdd0c946f4aab3f6ffbcfa5668b3e83cd5aeca0a2f"}, "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"},