From 1e382f069fc46ba074c78a456f6bd0b476125cd6 Mon Sep 17 00:00:00 2001 From: James Harton Date: Fri, 21 Jul 2023 19:07:17 +1200 Subject: [PATCH] chore: add Drone CI configuration --- .drone.yml | 494 ++++++++++++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 140 ------------- .tool-versions | 2 + README.md | 7 +- config/config.exs | 2 +- mix.exs | 2 +- 6 files changed, 501 insertions(+), 146 deletions(-) create mode 100644 .drone.yml delete mode 100644 .gitlab-ci.yml create mode 100644 .tool-versions diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..66ce87d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,494 @@ +kind: pipeline +type: docker +name: build + +steps: +- name: restore ASDF cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}' + mount: + - .asdf + +- name: restore build cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}' + mount: + - deps + - _build + - .hex + - .mix + - .rebar3 + +- name: install dependencies + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + ASDF_DIR: /root/.asdf + depends_on: + - restore ASDF cache + - restore build cache + commands: + - asdf_install + - rm -rf .asdf/downloads + - . $ASDF_DIR/asdf.sh + - mix local.hex --if-missing --force + - mix local.rebar --if-missing --force + - mix deps.get + - mix deps.compile + +- name: store ASDF cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + depends_on: + - install dependencies + settings: + rebuild: true + override: false + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}' + mount: + - .asdf + +- name: store build cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + depends_on: + - install dependencies + settings: + rebuild: true + override: false + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}' + mount: + - deps + - _build + - .hex + - .mix + - .rebar3 + +--- + +kind: pipeline +type: docker +name: test + +depends_on: + - build + +steps: +- name: restore ASDF cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}' + mount: + - .asdf + +- name: restore build cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}' + mount: + - deps + - _build + - .hex + - .mix + - .rebar3 + +- name: mix compile + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - restore ASDF cache + - restore build cache + commands: + - asdf mix local.hex --if-missing --force + - asdf mix local.rebar --if-missing --force + - asdf mix deps.get + - asdf mix deps.compile + - asdf mix compile --warnings-as-errors + +- name: mix test + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - mix compile + commands: + - asdf mix test + +- name: mix credo + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - mix compile + commands: + - asdf mix credo --strict + +- name: mix hex.audit + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - mix compile + commands: + - asdf mix hex.audit + +- name: mix format + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - mix compile + commands: + - asdf mix format --check-formatted + +- name: mix deps.unlock + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - mix compile + commands: + - asdf mix deps.unlock --check-unused + +- name: mix git_ops.check_message + image: code.harton.nz/james/asdf_container:latest + pull: "always" + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + depends_on: + - mix compile + commands: + - git log -1 --format=%s > .last_commit_message + - asdf mix git_ops.check_message .last_commit_message + +--- +kind: pipeline +type: docker +name: git ops + +trigger: + branch: + - main + event: + - push + +depends_on: + - test + +steps: +- name: restore ASDF cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}' + mount: + - .asdf + +- name: restore build cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}' + mount: + - deps + - _build + - .hex + - .mix + - .rebar3 + +- name: mix git_ops.release + image: code.harton.nz/james/asdf_container:latest + pull: "always" + depends_on: + - restore ASDF cache + - restore build cache + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + ASDF_DIR: /root/.asdf + DRONE_TOKEN: + from_secret: DRONE_TOKEN + commands: + - git fetch --tags + - . $ASDF_DIR/asdf.sh + - mix git_ops.project_info --format=shell > before.env + - mix git_ops.release --yes --no-major || true + - mix git_ops.project_info --format=shell > after.env + - . ./before.env + - export OLD_APP_VERSION=$${APP_VERSION} + - . ./after.env + - export NEW_APP_VERSION=$${APP_VERSION} + - if [ "v$${OLD_APP_VERSION}" != "v$${NEW_APP_VERSION}" ]; then + - export GIT_URL=$(echo $DRONE_GIT_HTTP_URL | sed -e "s/:\\/\\//:\\/\\/$DRONE_REPO_OWNER:$DRONE_TOKEN@/") + - git push $${GIT_URL} "HEAD:${DRONE_COMMIT_REF}" "refs/tags/v$${NEW_APP_VERSION}" + - fi + +--- + +kind: pipeline +type: docker +name: release + +trigger: + ref: + include: + - refs/tags/v** + +depends_on: + - test + +steps: +- name: restore ASDF cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}' + mount: + - .asdf + +- name: restore build cache + image: meltwater/drone-cache + pull: "always" + environment: + AWS_ACCESS_KEY_ID: + from_secret: ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: SECRET_ACCESS_KEY + AWS_PLUGIN_PATH_STYLE: true + settings: + restore: true + endpoint: + from_secret: S3_ENDPOINT + bucket: + from_secret: CACHE_BUCKET + region: us-east-1 + path-style: true + cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}' + mount: + - deps + - _build + - .hex + - .mix + - .rebar3 + +- name: build artifacts + image: code.harton.nz/james/asdf_container:latest + pull: "always" + depends_on: + - restore ASDF cache + - restore build cache + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + ASDF_DIR: /root/.asdf + commands: + - . $ASDF_DIR/asdf.sh + - mix git_ops.project_info --format=shell > app.env + - . ./app.env + - mkdir artifacts + - mix esbuild prod + - mix hex.build -o "artifacts/$${APP_NAME}-$${APP_VERSION}-pkg.tar" + - gzip "artifacts/$${APP_NAME}-$${APP_VERSION}-pkg.tar" + - mix docs + - tar zcvf "artifacts/$${APP_NAME}-$${APP_VERSION}-docs.tar.gz" doc/ + - git tag -l --format='%(contents:subject)' v$${APP_VERSION} > tag_subject + - git tag -l --format='%(contents:body)' v$${APP_VERSION} > tag_body + +- name: gitea release + image: plugins/gitea-release + depends_on: + - build artifacts + settings: + api_key: + from_secret: DRONE_TOKEN + base_url: https://code.harton.nz + files: artifacts/*.tar.gz + checksum: sha256 + title: tag_subject + note: tag_body + +- name: hex release + image: code.harton.nz/james/asdf_container:latest + pull: "always" + depends_on: + - restore ASDF cache + - restore build cache + environment: + MIX_ENV: test + HEX_HOME: /drone/src/.hex + MIX_HOME: /drone/src/.mix + REBAR_BASE_DIR: /drone/src/.rebar3 + ASDF_DATA_DIR: /drone/src/.asdf + ASDF_DIR: /root/.asdf + HEX_API_KEY: + from_secret: HEX_API_KEY + commands: + - . $ASDF_DIR/asdf.sh + - mix hex.publish --yes diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 2dc2500..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,140 +0,0 @@ -image: elixir:latest - -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" - -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: - 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: - - 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/.tool-versions b/.tool-versions new file mode 100644 index 0000000..44acbf0 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +erlang 26.0.2 +elixir 1.15.4 diff --git a/README.md b/README.md index 4eaad32..bf61117 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # G-code -[![pipeline status](https://gitlab.com/jimsy/gcode/badges/main/pipeline.svg)](https://gitlab.com/jimsy/gcode/commits/main) -[![Hex.pm](https://img.shields.io/hexpm/v/gcode.svg)](https://hex.pm/packages/gcode) +[![Build Status](https://drone.harton.nz/api/badges/james/gcode/status.svg?ref=refs/heads/main)](https://drone.harton.nz/james/gcode)[![Hex.pm](https://img.shields.io/hexpm/v/gcode.svg)](https://hex.pm/packages/gcode) [![Hippocratic License HL3-FULL](https://img.shields.io/static/v1?label=Hippocratic%20License&message=HL3-FULL&labelColor=5e2751&color=bc8c3d)](https://firstdonoharm.dev/version/3/0/full.html) `gcode` is an Elixir library for parsing and generating [G-code](https://en.wikipedia.org/wiki/G-code), which is a common language for working with CNC machines and 3D printers. @@ -18,7 +17,7 @@ Documentation for the main branch of this package is always available [on gitlab ## Contributing -This project uses the wonderful [git_ops](https://hex.pm/packages/git_ops) package to automate releases and as such requires the use of [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Feel free to open issues and pull requests. +This project uses the wonderful [git_ops](https://hex.pm/packages/git_ops) package to automate releases and as such requires the use of [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Feel free to open issues and pull requests. ## License @@ -27,7 +26,7 @@ This software is licensed under the terms of the this package for the terms. This license actively proscribes this software being used by and for some -industries, countries and activities. If your usage of this software doesn't +industries, countries and activities. If your usage of this software doesn't comply with the terms of this license, then [contact me](mailto:james@harton.nz) with the details of your use-case to organise the purchase of a license - the cost of which may include a donation to a suitable charity or NGO. diff --git a/config/config.exs b/config/config.exs index 6c02fee..b319ed1 100644 --- a/config/config.exs +++ b/config/config.exs @@ -3,7 +3,7 @@ import Config config :git_ops, mix_project: Mix.Project.get!(), changelog_file: "CHANGELOG.md", - repository_url: "https://gitlab.com/jimsy/gcode", + repository_url: "https://code.harton.nz/james/gcode", manage_mix_version?: true, manage_readme_version: "README.md", version_tag_prefix: "v" diff --git a/mix.exs b/mix.exs index 8a29f32..96cf153 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,7 @@ defmodule Gcode.MixProject do maintainers: ["James Harton "], licenses: ["HL3-FULL"], links: %{ - "Source" => "https://gitlab.com/jimsy/gcode" + "Source" => "https://code.harton.nz/james/gcode" } ] end