From 97a332b7631ac33f76f318f1458ecfcde1a2968f Mon Sep 17 00:00:00 2001 From: Cecilia Sanare Date: Thu, 22 Feb 2024 20:05:33 -0600 Subject: [PATCH] fix: setup automatic deployments --- .github/workflows/main.yml | 57 ++++++++++++++++++++++++++++++-------- .releaserc.yml | 6 ++++ 2 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 .releaserc.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b81246d..e965ca7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,8 +5,6 @@ on: branches: - main push: - tags: - - v* branches: - main @@ -32,8 +30,8 @@ jobs: name: Install Packages run: npm ci - verify: - name: Verify + lint: + name: Lint runs-on: ubuntu-latest needs: [install] steps: @@ -50,6 +48,23 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - name: Linting run: npm run lint + + coverage: + name: Coverage + runs-on: ubuntu-latest + needs: [install] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'npm' + - name: Cache Node Modules + id: cache-npm + uses: actions/cache@v3 + with: + path: node_modules/ + key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - name: Coverage run: npm run test:coverage - name: Coveralls @@ -83,11 +98,29 @@ jobs: - name: Build run: npm run build + semantic: + name: Semantic Release + runs-on: ubuntu-latest + needs: [lint, coverage, build] + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + outputs: + published: ${{ steps.semantic.outputs.new_release_published }} + major: ${{ steps.semantic.outputs.new_release_major_version }} + minor: ${{ steps.semantic.outputs.new_release_minor_version }} + patch: ${{ steps.semantic.outputs.new_release_patch_version }} + steps: + - uses: actions/checkout@v2 + - name: Semantic Release + id: semantic + uses: cycjimmy/semantic-release-action@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + deploy-docker: name: Deploy (Docker Hub) runs-on: ubuntu-latest - needs: [verify, build] - if: startsWith(github.ref, 'refs/tags/v') + needs: semantic + if: needs.semantic.outputs.published == 'true' steps: - uses: actions/checkout@v2 - name: Cache Node Modules @@ -116,13 +149,13 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v4 with: images: rainbowcafe/silvy tags: | - type=semver,pattern={{major}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{version}} + type=raw,value=${{ needs.semantic.outputs.major }} + type=raw,value=${{ needs.semantic.outputs.major }}.${{ needs.semantic.outputs.minor }} + type=raw,value=${{ needs.semantic.outputs.major }}.${{ needs.semantic.outputs.minor }}.${{ needs.semantic.outputs.patch }} - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc @@ -145,8 +178,8 @@ jobs: deploy-live: name: Deploy (Vercel) runs-on: ubuntu-latest - needs: [verify, build] - if: startsWith(github.ref, 'refs/tags/v') + needs: semantic + if: needs.semantic.outputs.new_release_published == 'true' steps: - uses: actions/checkout@v2 - name: Cache Node Modules diff --git a/.releaserc.yml b/.releaserc.yml new file mode 100644 index 0000000..b106a5d --- /dev/null +++ b/.releaserc.yml @@ -0,0 +1,6 @@ +branches: + - main +plugins: + - '@semantic-release/commit-analyzer' + - '@semantic-release/release-notes-generator' + - '@semantic-release/github' \ No newline at end of file