From 343c67402bc17a565cbdafebd57ba12528784707 Mon Sep 17 00:00:00 2001 From: David van der Spek Date: Fri, 9 Sep 2022 15:24:35 +0200 Subject: [PATCH] ENG-327: Plural release process (#421) * init elixir changes Signed-off-by: DavidSpek * extend generated release notes Signed-off-by: DavidSpek * have make use git tag Signed-off-by: DavidSpek * init add workflows Signed-off-by: DavidSpek * add push to Plural action Signed-off-by: DavidSpek * test fix removal of VERSION file in config.exs Signed-off-by: DavidSpek * fix git version in docker file Signed-off-by: DavidSpek * fix getting version from git tag for apps Signed-off-by: DavidSpek * cleanup make build command Signed-off-by: DavidSpek * remove unused phoenix code from dockerfile Signed-off-by: DavidSpek * cleanup tools download Signed-off-by: DavidSpek * cleanup old CI action Signed-off-by: DavidSpek * clean up version function Signed-off-by: DavidSpek Co-authored-by: michaeljguarino --- .dockerignore | 1 - .github/release.yml | 12 +- .github/workflows/publish.yaml | 204 ++++++++++++++++++++++++++ .github/workflows/push-to-plural.yaml | 30 ++++ .github/workflows/test.yaml | 100 ++++--------- Dockerfile | 111 ++++++++------ Makefile | 8 +- VERSION | 1 - apps/api/mix.exs | 32 +++- apps/core/mix.exs | 32 +++- apps/cron/mix.exs | 32 +++- apps/email/mix.exs | 32 +++- apps/graphql/mix.exs | 32 +++- apps/rtc/mix.exs | 32 +++- apps/worker/mix.exs | 32 +++- mix.exs | 32 +++- rel/config.exs | 10 +- 17 files changed, 588 insertions(+), 145 deletions(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/push-to-plural.yaml delete mode 100644 VERSION diff --git a/.dockerignore b/.dockerignore index eb9cf533c..7d7650039 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,7 +3,6 @@ deps/ charts/ .vscode/ log/ -.git/ .gitignore .dockerignore Dockerfile* diff --git a/.github/release.yml b/.github/release.yml index 9492856a1..e8faa2a54 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -4,10 +4,6 @@ changelog: exclude: labels: - ignore-for-release - authors: - - plural-bot - - renovate - - dependabot categories: - title: Breaking Changes ⚠️ labels: @@ -17,4 +13,10 @@ changelog: - enhancement - title: Bug Fixes 🐛 labels: - - bug-fix \ No newline at end of file + - bug-fix + - title: Dependency Updates + labels: + - dependencies + - title: Other Changes + labels: + - "*" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 000000000..4c0561ea9 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,204 @@ +name: CD / Plural + +on: + push: + tags: + - 'v*.*.*' +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: erlef/setup-beam@v1 + with: + elixir-version: '1.11.4' # Define the elixir version [required] + otp-version: '23.1.5' # Define the OTP version [required] + - uses: azure/setup-helm@v1 + with: + version: latest + - name: install plural cli + run: | + wget -O plural.o 'https://app.plural.sh/artifacts/plural/plural?platform=linux&arch=amd64' + chmod +x ./plural.o + cp ./plural.o /usr/local/bin/plural + - run: make testup + - name: Restore dependencies cache + uses: actions/cache@v2 + with: + path: deps + key: ${{ runner.os }}-mix-2-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-2 + - name: Restore _build + uses: actions/cache@v2 + with: + path: _build + key: ${{ runner.os }}-mix-2-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-2 + - run: mix deps.get + - run: mix test + - uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: workflow,job,repo,message,commit,author + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required + if: always() + publish: + name: Build and push Plural containers + runs-on: ubuntu-latest + needs: test + strategy: + matrix: + app: [ plural, cron, worker, rtc ] + permissions: + contents: 'read' + id-token: 'write' + packages: 'write' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Docker meta ${{ matrix.app }} + id: meta + uses: docker/metadata-action@v4 + with: + # list of Docker images to use as base name for tags + images: | + dkr.plural.sh/plural/${{ matrix.app }} + gcr.io/pluralsh/${{ matrix.app }} + ghcr.io/pluralsh/${{ matrix.app }} + # generate Docker tags based on the following events/attributes + tags: | + type=semver,pattern={{version}} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - uses: google-github-actions/auth@v0 + with: + workload_identity_provider: 'projects/${{ secrets.GOOGLE_PROJECT_ID }}/locations/global/workloadIdentityPools/github/providers/github' + service_account: 'terraform@pluralsh.iam.gserviceaccount.com' + token_format: 'access_token' + create_credentials_file: true + - uses: google-github-actions/setup-gcloud@v0.3.0 + - name: Login to gcr + run: gcloud auth configure-docker -q + - name: Login to plural registry + uses: docker/login-action@v2 + with: + registry: dkr.plural.sh + username: mjg@plural.sh + password: ${{ secrets.PLURAL_ACCESS_TOKEN }} + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push ${{ matrix.app }} + uses: docker/build-push-action@v3 + with: + context: "." + file: "./Dockerfile" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + APP_NAME=${{ matrix.app }} + GIT_COMMIT=$GITHUB_SHA + - name: slack webhook + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: workflow,job,repo,message,commit,author + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required + if: always() + publish-frontend: + name: Build and push Plural frontend container + runs-on: ubuntu-latest + needs: test + permissions: + contents: 'read' + id-token: 'write' + packages: 'write' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + # list of Docker images to use as base name for tags + images: | + dkr.plural.sh/plural/plural-www + gcr.io/pluralsh/plural-www + ghcr.io/pluralsh/plural-www + # generate Docker tags based on the following events/attributes + tags: | + type=semver,pattern={{version}} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - uses: google-github-actions/auth@v0 + with: + workload_identity_provider: 'projects/${{ secrets.GOOGLE_PROJECT_ID }}/locations/global/workloadIdentityPools/github/providers/github' + service_account: 'terraform@pluralsh.iam.gserviceaccount.com' + token_format: 'access_token' + create_credentials_file: true + - uses: google-github-actions/setup-gcloud@v0.3.0 + - name: Login to gcr + run: gcloud auth configure-docker -q + - name: Login to plural registry + uses: docker/login-action@v2 + with: + registry: dkr.plural.sh + username: mjg@plural.sh + password: ${{ secrets.PLURAL_ACCESS_TOKEN }} + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push ${{ matrix.app }} + uses: docker/build-push-action@v3 + with: + context: "./www" + file: "./www/Dockerfile" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + - name: slack webhook + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: workflow,job,repo,message,commit,author + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required + if: always() + release: + name: Create GitHub release + runs-on: ubuntu-latest + needs: publish + permissions: + contents: write + discussions: write + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true diff --git a/.github/workflows/push-to-plural.yaml b/.github/workflows/push-to-plural.yaml new file mode 100644 index 000000000..1bbdfb609 --- /dev/null +++ b/.github/workflows/push-to-plural.yaml @@ -0,0 +1,30 @@ +name: CD / Plural + +on: + push: + branches: + - "master" + paths: + - "plural/**" +jobs: + deploy: + name: Push Plural artifact to Plural + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: hashicorp/setup-terraform@v2 + - uses: azure/setup-helm@v2 + with: + version: latest + - name: installing plural + uses: pluralsh/setup-plural@v0.1.2 + with: + config: ${{ secrets.PLURAL_CONF }} + - run: make deploy + - uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: workflow,job,repo,message,commit,author + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required + if: always() diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 775f82a28..1f4065fa6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,22 +13,39 @@ jobs: matrix: app: [ plural, cron, worker, rtc ] steps: - - uses: actions/checkout@v3 - - id: version - uses: juliangruber/read-file-action@v1 + - name: Checkout + uses: actions/checkout@v3 with: - path: ./VERSION - - uses: docker/setup-qemu-action@v2 - - uses: docker/setup-buildx-action@v2 - - name: Build ${{ matrix.app }} image - uses: docker/build-push-action@v2 + fetch-depth: 0 + - name: Docker meta ${{ matrix.app }} + id: meta + uses: docker/metadata-action@v4 with: - context: . - file: ./Dockerfile + # list of Docker images to use as base name for tags + images: | + dkr.plural.sh/plural/${{ matrix.app }} + gcr.io/pluralsh/${{ matrix.app }} + ghcr.io/pluralsh/${{ matrix.app }} + # generate Docker tags based on the following events/attributes + tags: | + type=semver,pattern={{version}} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Test Build ${{ matrix.app }} image + uses: docker/build-push-action@v3 + with: + context: "." + file: "./Dockerfile" push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max build-args: | APP_NAME=${{ matrix.app }} - APP_VSN=${{ steps.version.outputs.content }} GIT_COMMIT=$GITHUB_SHA test: name: Test @@ -69,64 +86,3 @@ jobs: env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required if: always() - publish: - name: Publish - runs-on: ubuntu-latest - needs: test - if: github.ref == 'refs/heads/master' - strategy: - matrix: - app: [plural, cron, worker, rtc, www] - permissions: - contents: 'read' - id-token: 'write' - steps: - - uses: actions/checkout@v2 - - uses: google-github-actions/auth@v0 - with: - workload_identity_provider: 'projects/${{ secrets.GOOGLE_PROJECT_ID }}/locations/global/workloadIdentityPools/github/providers/github' - service_account: 'terraform@pluralsh.iam.gserviceaccount.com' - token_format: 'access_token' - create_credentials_file: true - - uses: google-github-actions/setup-gcloud@v0.6.0 - - name: Login to gcr - run: gcloud auth configure-docker -q - - name: Login to plural registry - uses: docker/login-action@v1 - with: - registry: dkr.plural.sh - username: mjg@plural.sh - password: ${{ secrets.PLURAL_ACCESS_TOKEN }} - - name: publish ${{ matrix.app }} - run: | - make build APP_NAME=${{ matrix.app }} GIT_COMMIT=$GITHUB_SHA - make push APP_NAME=${{ matrix.app }} - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: workflow,job,repo,message,commit,author - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: always() - deploy: - name: Deploy - runs-on: ubuntu-latest - needs: publish - steps: - - uses: actions/checkout@v2 - - uses: hashicorp/setup-terraform@v1 - - uses: azure/setup-helm@v1 - with: - version: latest - - name: installing plural - uses: pluralsh/setup-plural@v0.1.2 - with: - config: ${{ secrets.PLURAL_CONF }} - - run: make deploy - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: workflow,job,repo,message,commit,author - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: always() \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9974ccdd2..aecdf8956 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,20 +3,10 @@ FROM bitwalker/alpine-elixir:1.11.4 AS builder # The following are build arguments used to change variable parts of the image. # The name of your application/release (required) ARG APP_NAME -# The version of the application we are building (required) -ARG APP_VSN # The environment to build with ARG MIX_ENV=prod -# Set this to true if this release is not a Phoenix app -ARG SKIP_PHOENIX=true -# If you are using an umbrella project, you can change this -# argument to the directory the Phoenix app is in so that the assets -# can be built -ARG PHOENIX_SUBDIR=. - -ENV SKIP_PHOENIX=${SKIP_PHOENIX} \ - APP_NAME=${APP_NAME} \ - APP_VSN=${APP_VSN} \ + +ENV APP_NAME=${APP_NAME} \ MIX_ENV=${MIX_ENV} # By convention, /opt is typically used for applications @@ -26,8 +16,6 @@ WORKDIR /opt/app RUN apk update --allow-untrusted && \ apk upgrade --no-cache && \ apk add --no-cache \ - nodejs \ - yarn \ git \ build-base && \ mix local.rebar --force && \ @@ -36,45 +24,72 @@ RUN apk update --allow-untrusted && \ # This copies our app source code into the build container COPY . . -RUN mix do deps.get, compile +# needed so that we can get the app version from the git tag +RUN git config --global --add safe.directory '/opt/app' -# This step builds assets for the Phoenix app (if there is one) -# If you aren't building a Phoenix app, pass `--build-arg SKIP_PHOENIX=true` -# This is mostly here for demonstration purposes -RUN if [ ! "$SKIP_PHOENIX" = "true" ]; then \ - cd ${PHOENIX_SUBDIR}/assets && \ - yarn install && \ - yarn deploy && \ - cd - && \ - mix phx.digest; \ -fi +RUN mix do deps.get, compile RUN \ mkdir -p /opt/built && \ mix distillery.release --name ${APP_NAME} && \ - cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built && \ + cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/*/${APP_NAME}.tar.gz /opt/built && \ cd /opt/built && \ tar -xzf ${APP_NAME}.tar.gz && \ rm ${APP_NAME}.tar.gz -FROM dkr.plural.sh/plural/plural-cli:0.1.0 as cmd +FROM alpine:3.16.2 as tools -FROM erlang:23-alpine as helm +ARG TARGETARCH -ARG VERSION=3.3.1 +# renovate: datasource=github-releases depName=helm/helm +ENV HELM_VERSION=v3.9.3 -# ENV BASE_URL="https://storage.googleapis.com/kubernetes-helm" -ENV BASE_URL="https://get.helm.sh" -ENV TAR_FILE="helm-v${VERSION}-linux-amd64.tar.gz" +# renovate: datasource=github-releases depName=alco/goon +ENV GOON_VERSION=v1.1.1 + +# renovate: datasource=github-releases depName=pluralsh/plural-cli +ENV CLI_VERSION=v0.4.9 + +# renovate: datasource=github-releases depName=accurics/terrascan +ENV TERRASCAN_VERSION=v1.15.2 + +# renovate: datasource=github-releases depName=aquasecurity/trivy +ENV TRIVY_VERSION=v0.30.4 RUN apk add --update --no-cache curl ca-certificates unzip wget openssl && \ - curl -L ${BASE_URL}/${TAR_FILE} | tar xvz && \ - mv linux-amd64/helm /usr/local/bin/helm && \ + # download helm + curl -L https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz | tar xvz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/helm && \ + # download goon + curl -L https://github.com/alco/goon/releases/download/${GOON_VERSION}/goon_linux_${TARGETARCH}.tar.gz | tar xvz && \ + mv goon /usr/local/bin/goon && \ + # download plural cli + curl -L https://github.com/pluralsh/plural-cli/releases/download/${CLI_VERSION}/plural-cli_${CLI_VERSION/v/}_Linux_${TARGETARCH}.tar.gz | tar xvz plural && \ + mv plural /usr/local/bin/plural && \ + # download terrascan + if [ "$TARGETARCH" = "amd64" ]; then \ + curl -L https://github.com/accurics/terrascan/releases/download/${TERRASCAN_VERSION}/terrascan_${TERRASCAN_VERSION/v/}_Linux_x86_64.tar.gz > terrascan.tar.gz; \ + else \ + curl -L https://github.com/accurics/terrascan/releases/download/${TERRASCAN_VERSION}/terrascan_${TERRASCAN_VERSION/v/}_Linux_${TARGETARCH}.tar.gz > terrascan.tar.gz; \ + fi && \ + tar -xf terrascan.tar.gz terrascan && rm terrascan.tar.gz && \ + mv terrascan /usr/local/bin/terrascan && \ + # download trivy + if [ "$TARGETARCH" = "amd64" ]; then \ + curl -L https://github.com/aquasecurity/trivy/releases/download/${TRIVY_VERSION}/trivy_${TRIVY_VERSION/v/}_Linux-64bit.tar.gz > trivy.tar.gz; \ + elif [ "$TARGETARCH" = "arm64" ]; then \ + curl -L https://github.com/aquasecurity/trivy/releases/download/${TRIVY_VERSION}/trivy_${TRIVY_VERSION/v/}_Linux-ARM64.tar.gz > trivy.tar.gz; \ + fi && \ + tar -xf trivy.tar.gz trivy && rm trivy.tar.gz && \ + mv trivy /usr/local/bin/trivy && \ + # make tools executable chmod +x /usr/local/bin/helm && \ - curl -L https://github.com/alco/goon/releases/download/v1.1.1/goon_linux_amd64.tar.gz | tar xvz && \ - mv goon /usr/local/bin/goon && chmod +x /usr/local/bin/goon + chmod +x /usr/local/bin/goon && \ + chmod +x /usr/local/bin/plural && \ + chmod +x /usr/local/bin/terrascan && \ + chmod +x /usr/local/bin/trivy -FROM erlang:23-alpine +FROM erlang:23.3.4.16-alpine # The name of your application/release (required) ARG APP_NAME @@ -82,14 +97,12 @@ ARG GIT_COMMIT RUN apk update && \ apk add --no-cache \ - bash curl busybox \ - openssl-dev ca-certificates git - -RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.16.0 -RUN curl -L https://github.com/accurics/terrascan/releases/download/v1.9.0/terrascan_1.9.0_Linux_x86_64.tar.gz > terrascan.tar.gz && \ - tar -xf terrascan.tar.gz terrascan && rm terrascan.tar.gz && \ - chmod +x terrascan && \ - mv terrascan /usr/local/bin/terrascan + bash \ + curl \ + busybox \ + openssl-dev \ + ca-certificates \ + git ENV REPLACE_OS_VARS=true \ APP_NAME=${APP_NAME} \ @@ -97,9 +110,11 @@ ENV REPLACE_OS_VARS=true \ WORKDIR /opt/app -COPY --from=helm /usr/local/bin/helm /usr/local/bin/helm -COPY --from=cmd /go/bin/plural /usr/local/bin/plural -COPY --from=helm /usr/local/bin/goon /usr/local/bin/goon +COPY --from=tools /usr/local/bin/plural /usr/local/bin/plural +COPY --from=tools /usr/local/bin/helm /usr/local/bin/helm +COPY --from=tools /usr/local/bin/goon /usr/local/bin/goon +COPY --from=tools /usr/local/bin/terrascan /usr/local/bin/terrascan +COPY --from=tools /usr/local/bin/trivy /usr/local/bin/trivy COPY --from=builder /opt/built . CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground diff --git a/Makefile b/Makefile index e05451fb3..30ec6aecf 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,12 @@ GCP_PROJECT ?= pluralsh APP_NAME ?= plural -APP_VSN ?= `cat VERSION` +APP_VSN ?= `git describe` BUILD ?= `git rev-parse --short HEAD` DKR_HOST ?= dkr.plural.sh dep ?= forge-core GIT_COMMIT ?= abe123 +TARGETARCH ?= amd64 help: @perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @@ -18,8 +19,9 @@ ifeq ($(APP_NAME), www) -t gcr.io/$(GCP_PROJECT)/plural-www:`cat ../VERSION` \ -t $(DKR_HOST)/plural/plural-www:`cat ../VERSION` . else - docker build --build-arg APP_NAME=$(APP_NAME) --build-arg GIT_COMMIT=$(GIT_COMMIT) \ - --build-arg APP_VSN=$(APP_VSN) \ + docker build --build-arg APP_NAME=$(APP_NAME) \ + --build-arg GIT_COMMIT=$(GIT_COMMIT) \ + --build-arg TARGETARCH=$(TARGETARCH) \ -t $(APP_NAME):$(APP_VSN) \ -t $(APP_NAME):latest \ -t gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN) \ diff --git a/VERSION b/VERSION deleted file mode 100644 index 341cf11fa..000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.2.0 \ No newline at end of file diff --git a/apps/api/mix.exs b/apps/api/mix.exs index 613bcb43f..2e26c10e3 100644 --- a/apps/api/mix.exs +++ b/apps/api/mix.exs @@ -1,10 +1,40 @@ defmodule Api.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :api, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/core/mix.exs b/apps/core/mix.exs index 5b8f343cc..42c5bec94 100644 --- a/apps/core/mix.exs +++ b/apps/core/mix.exs @@ -1,10 +1,40 @@ defmodule Core.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :core, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/cron/mix.exs b/apps/cron/mix.exs index 774627e28..69bf78fb0 100644 --- a/apps/cron/mix.exs +++ b/apps/cron/mix.exs @@ -1,10 +1,40 @@ defmodule Cron.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :cron, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/email/mix.exs b/apps/email/mix.exs index df2fa70b0..8ca4b807a 100644 --- a/apps/email/mix.exs +++ b/apps/email/mix.exs @@ -1,10 +1,40 @@ defmodule Email.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :email, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/graphql/mix.exs b/apps/graphql/mix.exs index fd9d44580..87fab351c 100644 --- a/apps/graphql/mix.exs +++ b/apps/graphql/mix.exs @@ -1,10 +1,40 @@ defmodule Graphql.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :graphql, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/rtc/mix.exs b/apps/rtc/mix.exs index a408dee97..dcc971d14 100644 --- a/apps/rtc/mix.exs +++ b/apps/rtc/mix.exs @@ -1,10 +1,40 @@ defmodule Rtc.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :rtc, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/worker/mix.exs b/apps/worker/mix.exs index 02d54d4b9..bf5dc01b5 100644 --- a/apps/worker/mix.exs +++ b/apps/worker/mix.exs @@ -1,10 +1,40 @@ defmodule Worker.MixProject do use Mix.Project + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end + def project do [ app: :worker, - version: "0.1.0", + version: version(), build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/mix.exs b/mix.exs index 0dda37016..ff4d6f8f9 100644 --- a/mix.exs +++ b/mix.exs @@ -1,12 +1,40 @@ defmodule Plural.MixProject do use Mix.Project - @vsn File.read!("VERSION") + defp version do + version = git_vsn() + case Version.parse(version) do + {:ok, %Version{pre: ["pre" <> _ | _]} = version} -> + to_string(version) + + {:ok, %Version{pre: []} = version} -> + to_string(version) + + {:ok, %Version{patch: patch, pre: pre} = version} -> + to_string(%{version | patch: patch + 1, pre: ["dev" | pre]}) + + :error -> + Mix.shell().error("Failed to parse, falling back to 0.0.0") + "0.0.0" + end + end + + defp git_vsn() do + case System.cmd("git", ~w[describe --dirty=+dirty]) do + {version, 0} -> + String.trim_leading(String.trim(version), "v") + + {_, code} -> + Mix.shell().error("Git exited with code #{code}, falling back to 0.0.0") + + "0.0.0" + end + end def project do [ apps_path: "apps", - version: @vsn, + version: version(), start_permanent: Mix.env() == :prod, deps: deps() ] diff --git a/rel/config.exs b/rel/config.exs index 7b1747913..e930300f3 100644 --- a/rel/config.exs +++ b/rel/config.exs @@ -3,8 +3,6 @@ |> Path.wildcard() |> Enum.map(&Code.eval_file(&1)) -version = File.read!("VERSION") - use Distillery.Releases.Config, # This sets the default release built by `mix distillery.release` default_release: :default, @@ -33,7 +31,7 @@ environment :prod do end release :plural do - set version: version + set version: current_version(:api) set applications: [ :runtime_tools, api: :permanent, @@ -49,7 +47,7 @@ release :plural do end release :rtc do - set version: version + set version: current_version(:rtc) set applications: [ :runtime_tools, rtc: :permanent, @@ -59,7 +57,7 @@ release :rtc do end release :worker do - set version: version + set version: current_version(:worker) set applications: [ :runtime_tools, worker: :permanent, @@ -68,7 +66,7 @@ release :worker do end release :cron do - set version: version + set version: current_version(:cron) set applications: [ :runtime_tools, cron: :permanent,