From 1bcbe60f58cc1f043335fd44099276f00db78415 Mon Sep 17 00:00:00 2001 From: Travis Shivers Date: Sun, 23 Aug 2020 22:09:06 -0500 Subject: [PATCH] build(release): add semantic-release --- .github/workflows/docker-web.yml | 85 -------------------- .github/workflows/docker.yml | 85 -------------------- .github/workflows/release.yml | 131 +++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 170 deletions(-) delete mode 100644 .github/workflows/docker-web.yml delete mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/docker-web.yml b/.github/workflows/docker-web.yml deleted file mode 100644 index 6ad79aed..00000000 --- a/.github/workflows/docker-web.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Docker Web - -on: - push: - branches: master - tags: - - v* - -jobs: - buildx: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: get-npm-version - id: package-version - uses: martinbeentjes/npm-get-version-action@master - - - - name: Prepare - id: prepare - run: | - DOCKER_IMAGE=ttshivers/syncloungeweb - DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x - VERSION=latest - SOURCE_BRANCH=${GITHUB_REF#refs/heads/} - - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/v} - fi - - TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" - - echo ::set-output name=docker_image::${DOCKER_IMAGE} - echo ::set-output name=version::${VERSION} - echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ - --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ - --build-arg REVISION=${GITHUB_SHA:0:7} \ - --build-arg SOURCE_BRANCH=${SOURCE_BRANCH} \ - --build-arg VERSION=${{ steps.package-version.outputs.current-version}} \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache" \ - ${TAGS} --file ./Dockerfile.web ./ - - - name: Set up Docker Buildx - uses: crazy-max/ghaction-docker-buildx@v3 - - - name: Cache Docker layers - uses: actions/cache@v2 - id: cache - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-web-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-web-buildx- - - - name: Docker Buildx (build) - run: | - docker buildx build \ - --output "type=image,push=false" \ - ${{ steps.prepare.outputs.buildx_args }} - - - name: Docker Login - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: | - echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin - - - name: Docker Buildx (push) - run: | - docker buildx build \ - --output "type=image,push=true" \ - ${{ steps.prepare.outputs.buildx_args }} - - - name: Docker Check Manifest - run: | - docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} - - - name: Clear - if: always() - run: | - rm -f ${HOME}/.docker/config.json diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 83c425db..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Docker - -on: - push: - branches: master - tags: - - v* - -jobs: - buildx: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: get-npm-version - id: package-version - uses: martinbeentjes/npm-get-version-action@master - - - - name: Prepare - id: prepare - run: | - DOCKER_IMAGE=ttshivers/synclounge - DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x - VERSION=latest - SOURCE_BRANCH=${GITHUB_REF#refs/heads/} - - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/v} - fi - - TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" - - echo ::set-output name=docker_image::${DOCKER_IMAGE} - echo ::set-output name=version::${VERSION} - echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ - --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ - --build-arg REVISION=${GITHUB_SHA:0:7} \ - --build-arg SOURCE_BRANCH=${SOURCE_BRANCH} \ - --build-arg VERSION=${{ steps.package-version.outputs.current-version}} \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache" \ - ${TAGS} --file ./Dockerfile ./ - - - name: Set up Docker Buildx - uses: crazy-max/ghaction-docker-buildx@v3 - - - name: Cache Docker layers - uses: actions/cache@v2 - id: cache - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Docker Buildx (build) - run: | - docker buildx build \ - --output "type=image,push=false" \ - ${{ steps.prepare.outputs.buildx_args }} - - - name: Docker Login - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: | - echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin - - - name: Docker Buildx (push) - run: | - docker buildx build \ - --output "type=image,push=true" \ - ${{ steps.prepare.outputs.buildx_args }} - - - name: Docker Check Manifest - run: | - docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} - - - name: Clear - if: always() - run: | - rm -f ${HOME}/.docker/config.json \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..4471823a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,131 @@ +name: release + +on: + push: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2.1.1 + with: + node-version: 14 + - uses: actions/cache@v2 + with: + path: ~/.npm + key: client-${{ hashFiles('**/package-lock.json') }} + + - run: npm ci + - run: npm run lint + + release: + needs: test + + runs-on: ubuntu-latest + + outputs: + published: ${{ steps.release.outputs.published }} + release-version: ${{ steps.release.outputs.release-version }} + release-version-major: ${{ steps.release.outputs.release-version-major }} + release-version-minor: ${{ steps.release.outputs.release-version-minor }} + + steps: + - uses: actions/checkout@v2 + - run: npm ci + - id: release + name: semantic-release + uses: ahmadnassri/action-semantic-release@v1 + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + npm_config_unsafe_perm: true + + alias: + needs: release + if: needs.release.outputs.published == 'true' + runs-on: ubuntu-latest + strategy: + matrix: + alias: + - version: v${{ needs.release.outputs.release-version-major }} + - version: v${{ needs.release.outputs.release-version-major }}.${{ needs.release.outputs.release-version-minor }} + + steps: + - uses: actions/github-script@v3 + with: + script: | + const tag = 'tags/${{ matrix.alias.version }}' + const repo = { + owner: context.repo.owner, + repo: context.repo.repo + } + await github.git.deleteRef({ ...repo, ref: tag }).catch(() => {}) + await github.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA }) + buildx: + needs: release + if: needs.release.outputs.published == 'true' + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Prepare + id: prepare + run: | + DOCKER_IMAGE=${{ github.event.repository.full_name }} + DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x + + TAGS="--tag ${DOCKER_IMAGE}:latest --tag ${DOCKER_IMAGE}:${{ needs.release.outputs.release-version }} --tag ${DOCKER_IMAGE}:v${{ needs.release.outputs.release-version-major }}" + echo ::set-output name=docker_image::${DOCKER_IMAGE} + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ + --build-arg REVISION=${GITHUB_SHA:0:7} \ + --build-arg VERSION=${{ needs.release.outputs.release-version }} \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + ${TAGS} --file ./Dockerfile ./ + - + name: Set up Docker Buildx + uses: crazy-max/ghaction-docker-buildx@v3 + - + name: Cache Docker layers + uses: actions/cache@v2 + id: cache + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - + name: Docker Buildx (build) + run: | + docker buildx build \ + --output "type=image,push=false" \ + ${{ steps.prepare.outputs.buildx_args }} + - + name: Docker Login + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + - + name: Docker Buildx (push) + run: | + docker buildx build \ + --output "type=image,push=true" \ + ${{ steps.prepare.outputs.buildx_args }} + - + name: Docker Check Manifest + run: | + docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ needs.release.outputs.release-version }} + - + name: Clear + if: always() + run: | + rm -f ${HOME}/.docker/config.json