Add dev setup steps to build pipeline #14
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: build | |
on: | |
push: | |
branches: | |
- '*' | |
workflow_dispatch: | |
env: | |
NODE_VERSION: '20.x' | |
jobs: | |
install: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
with: | |
path: ./node_modules | |
key: "${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}" | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: Install node dependencies | |
run: npm ci | |
- name: Run postinstall | |
run: npm run postinstall | |
- name: Generate prisma types | |
run: | | |
cd apps/server-asset-sg/ | |
ng gen-prisma-client | |
test: | |
runs-on: ubuntu-latest | |
needs: install | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Restore cached node modules | |
uses: actions/cache@v2 | |
with: | |
path: ./node_modules | |
key: "${{ runner.os }}-npm-${{ steps.cache-node-modules.outputs.cache-key }}" | |
- name: Run tests | |
run: npm run test | |
lint: | |
runs-on: ubuntu-latest | |
needs: install | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Restore cached node modules | |
uses: actions/cache@v2 | |
with: | |
path: ./node_modules | |
key: "${{ runner.os }}-npm-${{ steps.cache-node-modules.outputs.cache-key }}" | |
- name: Run lint | |
run: npm run lint | |
# It would be cleaner and probably more performant to replace this build step | |
# with either a non-emitting build or a simple type check. | |
# We only have `build` available for now, | |
# since the project is currently split across a multitude of small packages, | |
# all of which have to specify their own commands. | |
# (Daniel von Atzigen, 2024-04-12) | |
build: | |
runs-on: ubuntu-latest | |
needs: | |
- test | |
- lint | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Restore cached node modules | |
uses: actions/cache@v2 | |
with: | |
path: ./node_modules | |
key: "${{ runner.os }}-npm-${{ steps.cache-node-modules.outputs.cache-key }}" | |
- name: Reset nx | |
run: npx nx reset | |
- name: Run build | |
run: npm run build | |
build_and_push_app: | |
name: 'build and push app' | |
if: github.event_name == 'push' && github.ref == 'refs/head/develop' | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create image | |
uses: ./.github/actions/create-image | |
with: | |
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-app | |
TAG: edge | |
DOCKERFILE: ./apps/client-asset-sg/docker/Dockerfile | |
build_and_push_api: | |
name: 'build and push api' | |
if: github.event_name == 'push' && github.ref == 'refs/head/develop' | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create image | |
uses: ./.github/actions/create-image | |
with: | |
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-api | |
TAG: edge | |
DOCKERFILE: ./apps/server-asset-sg/docker/Dockerfile | |
tag_edge_commit: | |
name: 'tag edge commit' | |
needs: build_and_push_api | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create/update tag | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/edge', | |
sha: context.sha | |
}).catch(err => { | |
if (err.status !== 422) throw err; | |
github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'tags/edge', | |
sha: context.sha | |
}); | |
}) | |
tag_rc_image: | |
name: tag rc image | |
if: github.event_name == 'push' && github.ref == 'refs/head/main' | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Login to GitHub Packages | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
- name: Pull docker image | |
run: docker pull ${{ vars.BASE_IMAGE_NAME }}-app:edge | |
- name: Tag docker image | |
run: docker tag ${{ vars.BASE_IMAGE_NAME }}-app:edge ${{ vars.BASE_IMAGE_NAME }}-app:release-candidate | |
- name: Push docker image | |
run: docker push ${{ vars.BASE_IMAGE_NAME }}-app:release-candidate | |
tag_rc_commit: | |
name: 'tag rc commit' | |
needs: tag_rc_image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create/update tag | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/release-candidate', | |
sha: context.sha | |
}).catch(err => { | |
if (err.status !== 422) throw err; | |
github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'tags/release-candidate', | |
sha: context.sha | |
}); | |
}) |