revert: testing skipping GA #4
This file contains 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: Deploy | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
outputs: | |
gateway-service: ${{ steps.filter.outputs.gateway-service }} | |
storefront: ${{ steps.filter.outputs.storefront }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
filters: | | |
gateway-service: | |
- 'apps/gateway-service/**' | |
- 'package.json' | |
storefront: | |
- 'apps/storefront/**' | |
- 'package.json' | |
push: | |
needs: changes | |
strategy: | |
matrix: | |
service: | |
- name: gateway-service | |
path: apps/gateway-service | |
package: "@cavaliercommerce/gateway-service" | |
dockerfile: apps/gateway-service/Dockerfile | |
- name: storefront | |
path: apps/storefront | |
package: "@cavaliercommerce/storefront" | |
dockerfile: apps/storefront/Dockerfile | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Check if should run | |
id: should-run | |
run: | | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" || "${{ needs.changes.outputs[matrix.service.name] }}" == "true" ]]; then | |
echo "run=true" >> $GITHUB_OUTPUT | |
else | |
echo "run=false" >> $GITHUB_OUTPUT | |
fi | |
- uses: actions/checkout@v4 | |
if: steps.should-run.outputs.run == 'true' | |
- name: Cache turbo build setup | |
if: steps.should-run.outputs.run == 'true' | |
uses: actions/cache@v4 | |
with: | |
path: .turbo | |
key: ${{ runner.os }}-turbo-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-turbo- | |
- uses: pnpm/action-setup@v4 | |
if: steps.should-run.outputs.run == 'true' | |
with: | |
version: 9.0.0 | |
- run: echo "node_version=$(cat .github/nodejs.version)" >> $GITHUB_ENV | |
if: steps.should-run.outputs.run == 'true' | |
- name: "Use node ${{ env.node_version }}" | |
if: steps.should-run.outputs.run == 'true' | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ env.node_version }}" | |
cache: "pnpm" | |
- name: Install dependencies | |
if: steps.should-run.outputs.run == 'true' | |
run: pnpm install | |
- name: Run tests | |
if: steps.should-run.outputs.run == 'true' | |
run: pnpm test --filter ${{ matrix.service.package }} | |
- name: Build image | |
if: steps.should-run.outputs.run == 'true' | |
run: docker build . --file ${{ matrix.service.dockerfile }} --tag ${{ matrix.service.name }} --label "runnumber=${GITHUB_RUN_ID}" | |
- name: Log in to registry | |
if: steps.should-run.outputs.run == 'true' | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Push image | |
if: steps.should-run.outputs.run == 'true' | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ matrix.service.name }} | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag ${{ matrix.service.name }} $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION |