Skip to content

feat: add release workflow for api (#6) #4

feat: add release workflow for api (#6)

feat: add release workflow for api (#6) #4

Workflow file for this run

name: Release
on:
push:
branches:
- main
- '[0-9]+.*'
jobs:
createReleaseVersion:
name: Create Release Version
runs-on: ubuntu-latest
outputs:
releaseVersion: ${{ steps.release.outputs.releaseVersion }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: |
npm ci
- name: Lint
run: |
npm run lint -- -- --no-fix --max-warnings 0
- name: Test
run: |
npm run test:unit:ci
- name: Create Release Version
id: release
env:
GITHUB_TOKEN: ${{ github.token }}
run: npx semantic-release
createReleaseDockerImages:
name: Create Release Docker Images
runs-on: [self-hosted, default]
needs: createReleaseVersion
if: ${{ needs.createReleaseVersion.outputs.releaseVersion != '' }}
steps:
- uses: actions/checkout@v3
- name: Set up Docker Build
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate build ID for Flux Image Automation
id: setVersionForFlux
run: |
sha=$(git rev-parse --short HEAD)
ts=$(date +%s%N | cut -b1-13)
echo "::set-output name=imageTag::${sha}-${ts}"
- name: Auth to google artifact registry
run: |
gcloud auth configure-docker us-docker.pkg.dev -q
- name: Build and push Docker image for API
uses: docker/build-push-action@v4
with:
push: true
tags: |
"matterlabs/block-explorer-api:latest"
"matterlabs/block-explorer-api:v${{ needs.createReleaseVersion.outputs.releaseVersion }}"
"matterlabs/block-explorer-api:${{ steps.setVersionForFlux.outputs.imageTag }}"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-api:latest"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-api:v${{ needs.createReleaseVersion.outputs.releaseVersion }}"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-api:${{ steps.setVersionForFlux.outputs.imageTag }}"
file: packages/api/Dockerfile
no-cache: true