Build and Release #69
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release | |
| on: | |
| pull_request: | |
| release: | |
| types: | |
| - published | |
| env: | |
| API_IMAGE_NAME: ghcr.io/smile-qwq/subtracker-api | |
| WEB_IMAGE_NAME: ghcr.io/smile-qwq/subtracker-web | |
| jobs: | |
| verify: | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Prisma generate | |
| run: npm run prisma:generate | |
| - name: Lint | |
| run: npm run lint | |
| - name: Test | |
| run: npm test | |
| - name: Build | |
| env: | |
| VITE_APP_VERSION: ${{ github.head_ref || github.ref_name }} | |
| run: npm run build | |
| release: | |
| if: github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Validate release tag | |
| id: release_tag | |
| shell: bash | |
| run: | | |
| TAG="${{ github.event.release.tag_name }}" | |
| if [[ ! "$TAG" =~ ^v[0-9]+(\.[0-9]+){1,2}(-[0-9A-Za-z.-]+)?$ ]]; then | |
| echo "Release tag must look like v1.0.0, v1.0.0-beta.1, or v1.0." >&2 | |
| exit 1 | |
| fi | |
| echo "value=$TAG" >> "$GITHUB_OUTPUT" | |
| - name: Checkout release tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.release.tag_name }} | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Prisma generate | |
| run: npm run prisma:generate | |
| - name: Lint | |
| run: npm run lint | |
| - name: Test | |
| run: npm test | |
| - name: Build | |
| env: | |
| VITE_APP_VERSION: ${{ steps.release_tag.outputs.value }} | |
| run: npm run build | |
| - name: Archive web dist | |
| run: | | |
| cd apps/web/dist | |
| zip -r ../../../subtracker-web-dist.zip . | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Extract API Docker metadata | |
| id: api_meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.API_IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.release_tag.outputs.value }} | |
| type=sha | |
| - name: Extract Web Docker metadata | |
| id: web_meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.WEB_IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.release_tag.outputs.value }} | |
| type=sha | |
| - name: Build and push API Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.api_meta.outputs.tags }} | |
| labels: ${{ steps.api_meta.outputs.labels }} | |
| - name: Build and push Web Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./docker/web.Dockerfile | |
| push: true | |
| build-args: | | |
| VITE_APP_VERSION=${{ steps.release_tag.outputs.value }} | |
| tags: ${{ steps.web_meta.outputs.tags }} | |
| labels: ${{ steps.web_meta.outputs.labels }} | |
| - name: Upload assets to GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.release_tag.outputs.value }} | |
| files: | | |
| subtracker-web-dist.zip |