From 52a9e6e43865de128d57e1b9510f5278b8ef9727 Mon Sep 17 00:00:00 2001 From: Chris Morabito Date: Thu, 1 Sep 2022 16:54:26 -0400 Subject: [PATCH] Add CI actions --- .github/workflows/actions.yaml | 124 ++++++++++++++++++ .../base-documentation-dialog.component.ts | 2 +- .../upload-dialog.component.html | 4 +- application/makefile | 14 +- cloudbuild-release.yaml | 11 -- cloudbuild.yaml | 33 ----- 6 files changed, 134 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/actions.yaml delete mode 100644 cloudbuild-release.yaml delete mode 100644 cloudbuild.yaml diff --git a/.github/workflows/actions.yaml b/.github/workflows/actions.yaml new file mode 100644 index 00000000..dfa72e15 --- /dev/null +++ b/.github/workflows/actions.yaml @@ -0,0 +1,124 @@ +name: Fleet Routing App CI +on: + push: +jobs: + # detect changes + changes: + runs-on: ubuntu-latest + outputs: + backend: ${{ steps.filter.outputs.backend }} + frontend: ${{ steps.filter.outputs.frontend }} + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + backend: + - 'application/backend/**' + frontend: + - 'application/frontend/**' + + # backend checks + check-backend: + needs: changes + if: ${{ needs.changes.outputs.backend == 'true' }} + + runs-on: ubuntu-latest + defaults: + run: + working-directory: application/backend + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js v16 LTS + uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'npm' + cache-dependency-path: application/backend/package-lock.json + + - run: npm ci + - run: npm run lint + - run: npm test + + # frontend checks + check-frontend: + needs: changes + if: ${{ needs.changes.outputs.frontend == 'true' }} + + runs-on: ubuntu-latest + defaults: + run: + working-directory: application/frontend + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js v16 LTS + uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'npm' + cache-dependency-path: application/frontend/package-lock.json + + - run: npm ci + - run: npm run lint + - run: npm run style-check + - run: Xvfb :99 & + - run: npm run test -- --watch=false --progress=false --browsers=ChromeHeadlessCI --code-coverage + env: + DISPLAY: ':99' + + # build container image + build-container: + needs: + - check-backend + - check-frontend + + runs-on: ubuntu-latest + container: google/cloud-sdk + env: + GCLOUD_SERVICE_ACCOUNT_JSON: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_JSON }} + SNAPSHOT_REGISTRY: ${{ secrets.SNAPSHOT_REGISTRY }} + COMMIT_TAG: ${{ github.sha }} + + steps: + - run: echo "COMMIT_TAG=$(echo $COMMIT_TAG | cut -c 1-7)" >> $GITHUB_ENV + + - run: echo $GCLOUD_SERVICE_ACCOUNT_JSON | base64 -d | docker login -u _json_key --password-stdin https://us-docker.pkg.dev + + - uses: actions/checkout@v3 + + - run: make build + - run: make push + + + # push container image + tag-release: + if: ${{ github.ref_type == 'tag' }} + + needs: + - build-container + + runs-on: ubuntu-latest + container: google/cloud-sdk + env: + GCLOUD_SERVICE_ACCOUNT_JSON: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_JSON }} + SNAPSHOT_REGISTRY: ${{ secrets.SNAPSHOT_REGISTRY }} + RELEASE_REGISTRY: ${{ secrets.RELEASE_REGISTRY }} + COMMIT_TAG: ${{ github.sha }} + RELEASE_TAG: ${{ github.ref_name }} + + steps: + - run: echo "COMMIT_TAG=$(echo $COMMIT_TAG | cut -c 1-7)" >> $GITHUB_ENV + + - run: echo $GCLOUD_SERVICE_ACCOUNT_JSON | base64 -d > /tmp/service-account.json + - run: gcloud auth activate-service-account --key-file=/tmp/service-account.json + + - uses: actions/checkout@v3 + + - run: make release + + # terraform checks diff --git a/application/frontend/src/app/core/components/base-documentation-dialog/base-documentation-dialog.component.ts b/application/frontend/src/app/core/components/base-documentation-dialog/base-documentation-dialog.component.ts index f8d20ef5..3e0c84c6 100644 --- a/application/frontend/src/app/core/components/base-documentation-dialog/base-documentation-dialog.component.ts +++ b/application/frontend/src/app/core/components/base-documentation-dialog/base-documentation-dialog.component.ts @@ -41,7 +41,7 @@ export class BaseDocumentationDialogComponent implements AfterViewInit, OnDestro this.http.get('assets/docs/documentation.md', { responseType: 'text' }).subscribe((data) => { marked.use({ baseUrl: 'assets/docs/', - renderer: this.buildRenderer() + renderer: this.buildRenderer(), }); this.dialogContent.nativeElement.innerHTML = marked(data); this.addListeners(); diff --git a/application/frontend/src/app/core/containers/upload-dialog/upload-dialog.component.html b/application/frontend/src/app/core/containers/upload-dialog/upload-dialog.component.html index 8b30c12e..a4b27e7f 100644 --- a/application/frontend/src/app/core/containers/upload-dialog/upload-dialog.component.html +++ b/application/frontend/src/app/core/containers/upload-dialog/upload-dialog.component.html @@ -3,8 +3,8 @@

Upload an existing scenario or solution

Have an existing vehicle routing problem you want to solve? You can upload a JSON description - of the problem to see the routes that Cloud Fleet Routing recommends, and then download the generated - routes if you wish. + of the problem to see the routes that Cloud Fleet Routing recommends, and then download the + generated routes if you wish.

You may also upload a zip file containing a scenario and its matching solution. In order to do diff --git a/application/makefile b/application/makefile index ac4a429f..04a9263e 100644 --- a/application/makefile +++ b/application/makefile @@ -1,16 +1,16 @@ .PHONY: build push release build: - docker build -t $(REGISTRY)/app:$(COMMIT_TAG) -f Dockerfile . + docker build -t $(REGISTRY):$(COMMIT_TAG) -f Dockerfile . push: - docker push $(REGISTRY)/app:$(COMMIT_TAG); + docker push $(REGISTRY):$(COMMIT_TAG); release: - $(eval DIGEST = $(shell gcloud container images list-tags $(SNAPSHOT_REGISTRY)/app --filter=$(COMMIT_TAG) --format='get(digest)')) + $(eval DIGEST = $(shell gcloud container images list-tags $(SNAPSHOT_REGISTRY) --filter=$(COMMIT_TAG) --format='get(digest)')) gcloud container images add-tag --quiet \ - $(SNAPSHOT_REGISTRY)/app@$(DIGEST) \ - $(RELEASE_REGISTRY)/app:$(COMMIT_TAG) \ - $(RELEASE_REGISTRY)/app:$(RELEASE_TAG) + $(SNAPSHOT_REGISTRY)@$(DIGEST) \ + $(RELEASE_REGISTRY):$(COMMIT_TAG) \ + $(RELEASE_REGISTRY):$(RELEASE_TAG) -default: build \ No newline at end of file +default: build diff --git a/cloudbuild-release.yaml b/cloudbuild-release.yaml deleted file mode 100644 index 6b807d9f..00000000 --- a/cloudbuild-release.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright 2022 Google LLC -# -# Use of this source code is governed by an MIT-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/MIT. - -# push container image to release registry -steps: - - name: 'gcr.io/cloud-builders/gcloud' - entrypoint: 'make' - args: ['release', 'COMMIT_TAG=$SHORT_SHA', 'RELEASE_TAG=$TAG_NAME', 'SNAPSHOT_REGISTRY=$_SNAPSHOT_REGISTRY', 'RELEASE_REGISTRY=$_RELEASE_REGISTRY'] diff --git a/cloudbuild.yaml b/cloudbuild.yaml deleted file mode 100644 index 76360e02..00000000 --- a/cloudbuild.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2022 Google LLC -# -# Use of this source code is governed by an MIT-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/MIT. - -# build container image -# push built image to snapshot registry -steps: - -- name: 'buildkite/puppeteer' - args: ['npm','install'] - dir: 'application/frontend' - -- name: 'buildkite/puppeteer' - args: ['npm', 'run', 'lint'] - dir: 'application/frontend' - -- name: 'buildkite/puppeteer' - args: ['npm', 'run', 'test', '--', '--no-watch', '--no-progress', '--browsers=ChromeHeadlessCI'] - dir: 'application/frontend' - -- name: 'gcr.io/cloud-builders/docker' - entrypoint: 'make' - args: [ 'build', 'COMMIT_TAG=$SHORT_SHA', 'SNAPSHOT_REGISTRY=$_SNAPSHOT_REGISTRY'] - -- name: 'gcr.io/cloud-builders/docker' - entrypoint: 'make' - args: [ 'push', 'COMMIT_TAG=$SHORT_SHA', 'SNAPSHOT_REGISTRY=$_SNAPSHOT_REGISTRY'] - -options: - machineType: E2_HIGHCPU_8 -timeout: 2400s