From 409e13e78321b0bd02f43f88f153a5c3467e837d Mon Sep 17 00:00:00 2001 From: James Harton Date: Mon, 21 Dec 2020 12:16:04 +1300 Subject: [PATCH] feat(git_ops): Auto-releasing using git_ops. --- .gitlab-ci.yml | 130 ++++++++++++++++++++++++++++++++++++++++------ CHANGELOG.md | 41 +++++++++++++++ README.md | 2 +- config/config.exs | 8 +++ mix.exs | 10 ++-- mix.lock | 2 + 6 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 88f6457..7fbe016 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,49 +1,93 @@ image: elixir:latest -cache: - key: "$CI_JOB_NAME" - paths: - - deps - - _build - - /root/.mix +stages: + - build + - test + - version + - 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 + artifacts: + paths: + - _build/ + - deps/ + - .hex + - .mix test: + image: elixir:latest + needs: + - job: build + artifacts: true stage: test script: - mix test integrate: + image: elixir:latest + needs: + - job: build + artifacts: true stage: test tags: - sense-hat script: + - mix clean - SENSE_HAT_PRESENT=true mix test credo: + image: elixir:latest + needs: + - job: build + artifacts: true stage: test script: - mix credo audit: + image: elixir:latest + needs: + - job: build + artifacts: true stage: test script: - mix hex.audit format: + image: elixir:latest + needs: + - job: build + artifacts: true stage: test script: - mix format --check-formatted pages: - stage: deploy + image: elixir:latest + needs: + - job: build + artifacts: true + stage: release script: - mix docs -o public artifacts: @@ -52,12 +96,66 @@ pages: only: - master -package: - stage: deploy +git_ops: + image: elixir:latest + needs: + - job: build + artifacts: true + - job: audit + - job: credo + - job: format + - job: test + stage: version only: - - /^v[0-9]+\.[0-9]+\.[0-9]+$/ + refs: + - master + except: + variables: + - $CI_COMMIT_MESSAGE =~ /chore\:\ release version/ script: - - mix hex.build + - | + 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 + mix git_ops.project_info -f shell > artifacts/env + source artifacts/env + 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}" artifacts: paths: - - "wafer-*.tar" + - artifacts/* + +release-gitlab: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + only: + - master + needs: + - job: git_ops + artifacts: true + script: + - | + source artifacts/env + 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 + needs: + - job: build + artifacts: true + - job: git_ops + stage: release + only: + - master + script: + - mix hex.publish --yes diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..de30ea1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,41 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](Https://conventionalcommits.org) for commit guidelines. + + + +## [v0.1.6](https://gitlab.com/jimsy/wafer/compare/v0.1.5...v0.1.6) (2020-12-26) + + + + +## [v0.1.5](https://gitlab.com/jimsy/wafer/compare/v0.1.4...v0.1.5) (2020-12-26) + + + + +## [v0.1.4](https://gitlab.com/jimsy/wafer/compare/v0.1.3...v0.1.4) (2020-12-26) + + + + +## [v0.1.3](https://gitlab.com/jimsy/wafer/compare/v0.1.2...v0.1.3) (2020-12-26) + + + + +## [v0.1.2](https://gitlab.com/jimsy/wafer/compare/v0.1.1...v0.1.2) (2020-12-26) + + + + +## [v0.1.1](https://gitlab.com/jimsy/wafer/compare/v0.1.0...v0.1.1) (2020-12-26) + + + + +## [v0.1.0](https://gitlab.com/jimsy/wafer/compare/v0.1.0...v0.1.0) (2020-12-20) + + + diff --git a/README.md b/README.md index d864752..d44fcc0 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ by adding `wafer` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:wafer, "~> 0.1"} + {:wafer, "~> 0.1.6"} ] end ``` diff --git a/config/config.exs b/config/config.exs index 0ea2df0..e9145ab 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,3 +1,11 @@ use Mix.Config config :wafer, Wafer.Driver.Fake, warn: Mix.env() != :test + +config :git_ops, + mix_project: Mix.Project.get!(), + changelog_file: "CHANGELOG.md", + repository_url: "https://gitlab.com/jimsy/wafer", + manage_mix_version?: true, + manage_readme_version: "README.md", + version_tag_prefix: "v" diff --git a/mix.exs b/mix.exs index 0186f28..4d29dbe 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,8 @@ defmodule Wafer.MixProject do Wafer is an Elixir library to make writing drivers for i2c and SPI connected peripherals and interacting with GPIO pins easier. """ - @version "0.1.0" + + @version "0.1.6" def project do [ @@ -45,10 +46,11 @@ defmodule Wafer.MixProject do {:circuits_gpio, "~> 0.4", optional: true}, {:circuits_i2c, "~> 0.3", optional: true}, {:circuits_spi, "~> 0.1", 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.2", only: ~w[dev test]a, runtime: false}, {:mimic, "~> 1.1", only: :test} ] end diff --git a/mix.lock b/mix.lock index 7953d6a..7b41eef 100644 --- a/mix.lock +++ b/mix.lock @@ -10,6 +10,8 @@ "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"}, "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.2.0", "27a2e38cf5d71ebdd287c90006c0a41dee8b2309369f8a97d3f6e3a2c279fe2f", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "6fa296bb9c2d737efba7ef52f3e6cdfafeb6a599db97f65c29b56e09f29b67e0"}, "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"}, "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"},