From 447e6be2e35fe3776a611d2017a107ad20229593 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 23 May 2024 11:33:20 +0000 Subject: [PATCH 01/28] add prettier --- .submodules/config/configs.jsonc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.submodules/config/configs.jsonc b/.submodules/config/configs.jsonc index c3ebab2a..c113380b 100644 --- a/.submodules/config/configs.jsonc +++ b/.submodules/config/configs.jsonc @@ -91,7 +91,8 @@ "customizations": { "vscode": { "extensions": [ - "dbaeumer.vscode-eslint" + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" // "dsznajder.es7-react-js-snippets", // "ecmel.vscode-html-css", // "jock.svg" @@ -101,7 +102,27 @@ }, "vscode": { "settings": { - "typescript.preferences.quoteStyle": "single" + "javascript.format.semicolons": "remove", + "typescript.format.semicolons": "remove", + "javascript.preferences.quoteStyle": "double", + "typescript.preferences.quoteStyle": "double", + "prettier.singleQuote": false, + "[javascript]": { + "editor.tabSize": 2, + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[javascriptreact]": { + "editor.tabSize": 2, + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescript]": { + "editor.tabSize": 2, + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescriptreact]": { + "editor.tabSize": 2, + "editor.defaultFormatter": "esbenp.prettier-vscode" + } }, "codeSnippets": { "javascript.module.doccomment": { From a2b73bec220b1ae73063b5a3ab85714f6648a9dc Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 23 May 2024 13:08:08 +0000 Subject: [PATCH 02/28] setup a javascript environment --- .../javascript/setup-environment/action.yaml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/actions/javascript/setup-environment/action.yaml diff --git a/.github/actions/javascript/setup-environment/action.yaml b/.github/actions/javascript/setup-environment/action.yaml new file mode 100644 index 00000000..da8b903c --- /dev/null +++ b/.github/actions/javascript/setup-environment/action.yaml @@ -0,0 +1,42 @@ +name: "Code for Life - JavaScript - Setup Environment" +description: "Set up a JavaScript environment." +inputs: + checkout: + description: "A flag to designate if the code should be checked out." + required: true + default: "true" + node-version: + description: "The Node.js version to set up." + required: true + default: "18" + working-directory: + description: "The current working directory." + required: true + default: "." + install-args: + description: "Arguments to pass to pipenv install." + required: false +runs: + using: composite + steps: + - name: ๐Ÿ›ซ Checkout + if: ${{ inputs.checkout == 'true' }} + uses: actions/checkout@v4 + + - name: ๐ŸŒ Set up Node + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + + - name: โฌ†๏ธ Upgrade npm + shell: bash + run: npm install --global npm + + - name: ๐Ÿ›  Install Yarn + shell: bash + run: npm install --global yarn + + - name: ๐Ÿ›  Install Dependencies + shell: bash + working-directory: ${{ inputs.working-directory }} + run: yarn install ${{ inputs.install-args }} From e16625f682ed85e466711d718014f68b66d6a511 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 23 May 2024 13:28:27 +0000 Subject: [PATCH 03/28] add test js code workflow --- .github/workflows/test-javascript-code.yaml | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/test-javascript-code.yaml diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml new file mode 100644 index 00000000..f2bb2477 --- /dev/null +++ b/.github/workflows/test-javascript-code.yaml @@ -0,0 +1,72 @@ +name: Test JavaScript Code + +on: + workflow_call: + inputs: + node-version: + description: "The Node.js version to set up." + type: number + required: false + default: 18 + working-directory: + description: "The current working directory." + type: string + required: false + default: "." + # codecov-slug: + # description: "The slug provided to Codecov for the coverage report." + # type: string + # required: false + # default: ${{ github.repository }} + # codecov-yml-path: + # description: "The path of the Codecov YAML file." + # type: string + # required: false + # default: "./codecov.yml" + # secrets: + # CODECOV_TOKEN: + # description: "The token used to gain access to Codecov." + # required: false + +jobs: + test-js-code: + runs-on: ubuntu-latest + # env: + # COVERAGE_REPORT: coverage.xml # NOTE: COVERAGE_FILE is reserved - do not use. + # OCADO_TECH_ORG_ID: 2088731 + steps: + - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment + uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@configure_js_services # TODO: set to @main + with: + node-version: ${{ inputs.node-version }} + working-directory: ${{ inputs.working-directory }} + install-args: --production=false + + - name: ๐Ÿ”Ž Check Code Format + working-directory: ${{ inputs.working-directory }} + run: yarn format:check + + - name: ๐Ÿ”Ž Check Static Type Hints + working-directory: ${{ inputs.working-directory }} + run: yarn type-check + + - name: ๐Ÿ”Ž Check Static Code + working-directory: ${{ inputs.working-directory }} + run: yarn lint + + # TODO: generate code coverage + - name: ๐Ÿงช Test Code Units + working-directory: ${{ inputs.working-directory }} + run: yarn test + + # TODO + # - name: ๐Ÿ“ˆ Upload Coverage Reports to Codecov + # if: github.repository_owner_id == env.OCADO_TECH_ORG_ID + # uses: codecov/codecov-action@v4 + # with: + # fail_ci_if_error: true + # token: ${{ secrets.CODECOV_TOKEN }} + # slug: ${{ inputs.codecov-slug }} + # codecov_yml_path: ${{ inputs.codecov-yml-path }} + # working-directory: ${{ inputs.working-directory }} + # file: ${{ env.COVERAGE_REPORT }} From fb8eac5d3116342d6df6c657e31ae5496e7758c5 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 23 May 2024 17:31:40 +0000 Subject: [PATCH 04/28] add path to prettier config file --- .submodules/config/configs.jsonc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.submodules/config/configs.jsonc b/.submodules/config/configs.jsonc index c113380b..df3e64bd 100644 --- a/.submodules/config/configs.jsonc +++ b/.submodules/config/configs.jsonc @@ -106,7 +106,7 @@ "typescript.format.semicolons": "remove", "javascript.preferences.quoteStyle": "double", "typescript.preferences.quoteStyle": "double", - "prettier.singleQuote": false, + "!prettier.configPath": ".prettierrc.json", "[javascript]": { "editor.tabSize": 2, "editor.defaultFormatter": "esbenp.prettier-vscode" @@ -338,7 +338,8 @@ "black-formatter.cwd": "${workspaceFolder}/backend", "mypy-type-checker.cwd": "${workspaceFolder}/backend", "pylint.cwd": "${workspaceFolder}/backend", - "python.testing.cwd": "${workspaceFolder}/backend" + "python.testing.cwd": "${workspaceFolder}/backend", + "!prettier.configPath": "frontend/.prettierrc.json" }, "tasks": { "version": "2.0.0", From 74bdaa0220bfbdcee14d9c1e414fad8e63aa9447 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 23 May 2024 17:31:59 +0000 Subject: [PATCH 05/28] upload coverage to codecov --- .github/workflows/test-javascript-code.yaml | 57 ++++++++++----------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml index f2bb2477..7cf0862b 100644 --- a/.github/workflows/test-javascript-code.yaml +++ b/.github/workflows/test-javascript-code.yaml @@ -13,27 +13,26 @@ on: type: string required: false default: "." - # codecov-slug: - # description: "The slug provided to Codecov for the coverage report." - # type: string - # required: false - # default: ${{ github.repository }} - # codecov-yml-path: - # description: "The path of the Codecov YAML file." - # type: string - # required: false - # default: "./codecov.yml" - # secrets: - # CODECOV_TOKEN: - # description: "The token used to gain access to Codecov." - # required: false + codecov-slug: + description: "The slug provided to Codecov for the coverage report." + type: string + required: false + default: ${{ github.repository }} + codecov-yml-path: + description: "The path of the Codecov YAML file." + type: string + required: false + default: "./codecov.yml" + secrets: + CODECOV_TOKEN: + description: "The token used to gain access to Codecov." + required: false jobs: test-js-code: runs-on: ubuntu-latest - # env: - # COVERAGE_REPORT: coverage.xml # NOTE: COVERAGE_FILE is reserved - do not use. - # OCADO_TECH_ORG_ID: 2088731 + env: + OCADO_TECH_ORG_ID: 2088731 steps: - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@configure_js_services # TODO: set to @main @@ -54,19 +53,17 @@ jobs: working-directory: ${{ inputs.working-directory }} run: yarn lint - # TODO: generate code coverage - name: ๐Ÿงช Test Code Units working-directory: ${{ inputs.working-directory }} - run: yarn test + run: yarn test:coverage - # TODO - # - name: ๐Ÿ“ˆ Upload Coverage Reports to Codecov - # if: github.repository_owner_id == env.OCADO_TECH_ORG_ID - # uses: codecov/codecov-action@v4 - # with: - # fail_ci_if_error: true - # token: ${{ secrets.CODECOV_TOKEN }} - # slug: ${{ inputs.codecov-slug }} - # codecov_yml_path: ${{ inputs.codecov-yml-path }} - # working-directory: ${{ inputs.working-directory }} - # file: ${{ env.COVERAGE_REPORT }} + - name: ๐Ÿ“ˆ Upload Coverage Reports to Codecov + if: github.repository_owner_id == env.OCADO_TECH_ORG_ID + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + slug: ${{ inputs.codecov-slug }} + codecov_yml_path: ${{ inputs.codecov-yml-path }} + working-directory: ${{ inputs.working-directory }} + file: coverage/coverage-final.json From c402145396b37beba0146ad1830ef20f1676dd41 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 23 May 2024 17:59:04 +0000 Subject: [PATCH 06/28] codecov file input --- .github/workflows/test-javascript-code.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml index 7cf0862b..17e1b6ad 100644 --- a/.github/workflows/test-javascript-code.yaml +++ b/.github/workflows/test-javascript-code.yaml @@ -23,6 +23,11 @@ on: type: string required: false default: "./codecov.yml" + codecov-file: + description: "The path to the coverage file to upload." + type: string + required: false + default: "coverage/cobertura-coverage.xml" secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." @@ -66,4 +71,4 @@ jobs: slug: ${{ inputs.codecov-slug }} codecov_yml_path: ${{ inputs.codecov-yml-path }} working-directory: ${{ inputs.working-directory }} - file: coverage/coverage-final.json + file: ${{ inputs.codecov-file }} From ff36496bd456ca0f9c7746e3d6e050f0252b0303 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 10:54:50 +0100 Subject: [PATCH 07/28] add portal-frontend submodule --- .gitmodules | 3 +++ codeforlife-portal-frontend | 1 + 2 files changed, 4 insertions(+) create mode 160000 codeforlife-portal-frontend diff --git a/.gitmodules b/.gitmodules index e21ceb93..2de7c9ff 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "codeforlife-sso"] path = codeforlife-sso url = https://github.com/ocadotechnology/codeforlife-sso.git +[submodule "codeforlife-portal-frontend"] + path = codeforlife-portal-frontend + url = https://github.com/ocadotechnology/codeforlife-portal-frontend.git diff --git a/codeforlife-portal-frontend b/codeforlife-portal-frontend new file mode 160000 index 00000000..bc3a3c5d --- /dev/null +++ b/codeforlife-portal-frontend @@ -0,0 +1 @@ +Subproject commit bc3a3c5d439329503bbed8c5c3e24125c5d608dc From 0e75520b813d25577b98ff768afc258b9be114e5 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 13:59:40 +0100 Subject: [PATCH 08/28] fix config to support FE and BE repos --- .submodules/config/configs.jsonc | 210 ++++++++++++++++--------------- 1 file changed, 112 insertions(+), 98 deletions(-) diff --git a/.submodules/config/configs.jsonc b/.submodules/config/configs.jsonc index df3e64bd..b3057f23 100644 --- a/.submodules/config/configs.jsonc +++ b/.submodules/config/configs.jsonc @@ -74,14 +74,11 @@ } } }, - "javascript": { + "javascript.devcontainer": { "inherits": [ "base" ], "description": "A devcontainer with a javascript environment.", - "submodules": [ - "codeforlife-package-javascript" - ], "devcontainer": { "features": { "ghcr.io/devcontainers/features/node:1": { @@ -93,13 +90,16 @@ "extensions": [ "dbaeumer.vscode-eslint", "esbenp.prettier-vscode" - // "dsznajder.es7-react-js-snippets", - // "ecmel.vscode-html-css", - // "jock.svg" ] } } - }, + } + }, + "javascript.config": { + "inherits": [ + "base" + ], + "description": "A configured javascript environment.", "vscode": { "settings": { "javascript.format.semicolons": "remove", @@ -107,22 +107,7 @@ "javascript.preferences.quoteStyle": "double", "typescript.preferences.quoteStyle": "double", "!prettier.configPath": ".prettierrc.json", - "[javascript]": { - "editor.tabSize": 2, - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[javascriptreact]": { - "editor.tabSize": 2, - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[typescript]": { - "editor.tabSize": 2, - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[typescriptreact]": { - "editor.tabSize": 2, - "editor.defaultFormatter": "esbenp.prettier-vscode" - } + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "codeSnippets": { "javascript.module.doccomment": { @@ -142,17 +127,21 @@ } } }, - "python": { + "javascript": { "inherits": [ - "base" + "javascript.devcontainer", + "javascript.config" ], - "description": "A devcontainer with a python environment.", + "description": "A devcontainer with a configured javascript environment.", "submodules": [ - "codeforlife-deploy-appengine", - "codeforlife-package-python", - "codeforlife-portal", - "rapid-router" + "codeforlife-package-javascript" + ] + }, + "python.devcontainer": { + "inherits": [ + "base" ], + "description": "A devcontainer with a python environment.", "devcontainer": { "features": { "ghcr.io/devcontainers/features/python:1": { @@ -178,7 +167,13 @@ ] } } - }, + } + }, + "python.config": { + "inherits": [ + "base" + ], + "description": "A configured python environment.", "vscode": { "settings": { "python.defaultInterpreterPath": ".venv/bin/python", @@ -303,74 +298,71 @@ } } }, - "service": { + "python": { "inherits": [ - "javascript", - "python" + "python.devcontainer", + "python.config" ], - "description": "A devcontainer for a micro-service.", + "description": "A devcontainer with a configured python environment.", "submodules": [ - "codeforlife-service-template", - "codeforlife-portal-react", - "codeforlife-sso" + "codeforlife-deploy-appengine", + "codeforlife-package-python", + "codeforlife-portal", + "rapid-router" + ] + }, + "service.devcontainer": { + "inherits": [ + "python.devcontainer", + "javascript.devcontainer" ], + "description": "The devcontainer for a micro-service.", "devcontainer": { - "postCreateCommand": "./setup", + "postCreateCommand": "chmod u+x ./setup && ./setup", "mounts": [ "source=./codeforlife-package-javascript,target=/workspace/codeforlife-package-javascript,type=bind,consistency=cached", "source=./codeforlife-package-python,target=/workspace/codeforlife-package-python,type=bind,consistency=cached" ] }, + "workspace": { + "folders": [ + { + "path": "../codeforlife-package-python", + "name": "package-python" + }, + { + "path": "../codeforlife-package-javascript", + "name": "package-javascript" + } + ] + } + }, + "service.backend": { + "inherits": [ + "service.devcontainer", + "python.config" + ], + "description": "A devcontainer for a backend micro-service.", + "submodules": [ + "codeforlife-portal-react" + ], "vscode": { "settings": { - "python.defaultInterpreterPath": "backend/.venv/bin/python", "python.analysis.extraPaths": [ "../codeforlife-package-python" - ], - "!isort.path": [ - "backend/.venv/bin/python", - "-m", - "isort" - ], - "!isort.args": [ - "--settings-file=backend/pyproject.toml" - ], - "black-formatter.cwd": "${workspaceFolder}/backend", - "mypy-type-checker.cwd": "${workspaceFolder}/backend", - "pylint.cwd": "${workspaceFolder}/backend", - "python.testing.cwd": "${workspaceFolder}/backend", - "!prettier.configPath": "frontend/.prettierrc.json" + ] }, "tasks": { "version": "2.0.0", "tasks": [ - { - "label": "start-react-dev-server", - "isBackground": true, - "type": "npm", - "script": "start", - "options": { - "env": { - "BROWSER": "none" - } - }, - "path": "frontend", - "problemMatcher": [] - }, { "label": "pipenv-install-dev", "type": "shell", - "options": { - "cwd": "${workspaceFolder}/backend" - }, "command": "pipenv install --dev" }, { "label": "migrate-db", "type": "shell", - "options": { - "cwd": "${workspaceFolder}/backend" - }, "dependsOn": [ "pipenv-install-dev" ], @@ -381,20 +373,13 @@ "launch": { "version": "0.2.0", "configurations": [ - { - "name": "React Dev Server", - "type": "chrome", - "request": "launch", - "url": "http://localhost:3000", - "preLaunchTask": "start-react-dev-server" - }, { "name": "Django Server", "type": "debugpy", "request": "launch", "django": true, "justMyCode": false, - "program": "${workspaceFolder}/backend/manage.py", + "program": "${workspaceFolder}/manage.py", "?args": [ "runserver", "localhost:8000" @@ -403,23 +388,52 @@ } ] } - }, - "workspace": { - "folders": [ - { - "path": "../codeforlife-package-python", - "name": "package-python" - }, - { - "path": "../codeforlife-package-javascript", - "name": "package-javascript" - } - ] + } + }, + "service.frontend": { + "inherits": [ + "service.devcontainer", + "javascript.config" + ], + "description": "A devcontainer for a frontend micro-service.", + "submodules": [ + "codeforlife-portal-frontend" + ], + "vscode": { + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "start-react-dev-server", + "isBackground": true, + "type": "npm", + "script": "start", + "options": { + "env": { + "BROWSER": "none" + } + }, + "problemMatcher": [] + } + ] + }, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "React Dev Server", + "type": "chrome", + "request": "launch", + "url": "http://localhost:5173", + "preLaunchTask": "start-react-dev-server" + } + ] + } } }, "service+sso": { "inherits": [ - "service" + "service.devcontainer" ], "description": "A service that also runs the SSO service in the background.", // TODO: set submodules after testing how this would work. @@ -438,9 +452,9 @@ "type": "shell", "isBackground": true, "options": { - "cwd": "${workspaceFolder}/../codeforlife-sso/backend", + "cwd": "${workspaceFolder}/../codeforlife-sso", "env": { - "DB_NAME": "${fileWorkspaceFolder}/backend/db.sqlite3", + "DB_NAME": "${fileWorkspaceFolder}/db.sqlite3", "SERVICE_NAME": "sso", "SERVICE_PORT": "8001" } @@ -461,7 +475,7 @@ "request": "launch", "django": true, "justMyCode": false, - "program": "${fileWorkspaceFolder}/backend/manage.py", + "program": "${fileWorkspaceFolder}/manage.py", "args": [ "runserver", "localhost:8000" From 947021b331eaa5b523be575c20ccc0c56c7dff69 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 14:22:21 +0100 Subject: [PATCH 09/28] gcloud deploy app action --- .github/actions/gcloud/deploy-app/action.yaml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/actions/gcloud/deploy-app/action.yaml diff --git a/.github/actions/gcloud/deploy-app/action.yaml b/.github/actions/gcloud/deploy-app/action.yaml new file mode 100644 index 00000000..ae35ae4d --- /dev/null +++ b/.github/actions/gcloud/deploy-app/action.yaml @@ -0,0 +1,23 @@ +name: "Code for Life - GCloud - Deploy App" +description: "Deploy an app to Google Cloud." +inputs: + gcp-credentials: + description: "The JSON credentials uses to access GCP." + required: true + deploy-args: + description: "Arguments to pass to `gcloud app deploy`." + required: false +runs: + using: composite + steps: + - name: ๐Ÿ— Authenticate with GCloud + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ inputs.gcp-credentials }} + + - name: ๐Ÿค– Set up GCloud SDK + uses: google-github-actions/setup-gcloud@v2 + + - name: ๐Ÿš€ Deploy App on GCloud + shell: bash + run: gcloud app deploy ${{ inputs.deploy-args }} From c37e4f797e0c5b2a9e98910e6cbab06b44effea2 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 15:01:37 +0100 Subject: [PATCH 10/28] create frontend workflow --- .github/actions/gcloud/deploy-app/action.yaml | 2 +- .github/workflows/frontend.yaml | 30 +++++++++++++++++++ .github/workflows/test-javascript-code.yaml | 2 +- .github/workflows/test-python-code.yaml | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/frontend.yaml diff --git a/.github/actions/gcloud/deploy-app/action.yaml b/.github/actions/gcloud/deploy-app/action.yaml index ae35ae4d..25310fd6 100644 --- a/.github/actions/gcloud/deploy-app/action.yaml +++ b/.github/actions/gcloud/deploy-app/action.yaml @@ -2,7 +2,7 @@ name: "Code for Life - GCloud - Deploy App" description: "Deploy an app to Google Cloud." inputs: gcp-credentials: - description: "The JSON credentials uses to access GCP." + description: "The JSON credentials used to access GCP." required: true deploy-args: description: "Arguments to pass to `gcloud app deploy`." diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml new file mode 100644 index 00000000..3f05a500 --- /dev/null +++ b/.github/workflows/frontend.yaml @@ -0,0 +1,30 @@ +name: Frontend + +on: + workflow_call: + secrets: + CODECOV_TOKEN: + description: "The token used to gain access to Codecov." + required: true + GCP_CREDENTIALS: + description: "The JSON credentials used to access GCP." + required: true + +jobs: + test: + uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@configure_js_services # TODO: set to @main + secrets: inherit + + deploy: + runs-on: ubuntu-latest + needs: [test] + # if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' + environment: ${{ github.ref_name }} + steps: + - name: ๐Ÿ›ซ Checkout + uses: actions/checkout@v4 + + - name: ๐Ÿš€ Deploy App on GCloud + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main + with: + gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml index 17e1b6ad..e81c7bba 100644 --- a/.github/workflows/test-javascript-code.yaml +++ b/.github/workflows/test-javascript-code.yaml @@ -31,7 +31,7 @@ on: secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." - required: false + required: true jobs: test-js-code: diff --git a/.github/workflows/test-python-code.yaml b/.github/workflows/test-python-code.yaml index f763223e..784cf973 100644 --- a/.github/workflows/test-python-code.yaml +++ b/.github/workflows/test-python-code.yaml @@ -41,7 +41,7 @@ on: secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." - required: false + required: true jobs: test-py-code: From d420b79ef717e8122f7cadc81e898035c9940e64 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 15:19:08 +0100 Subject: [PATCH 11/28] deploy to gcp --- .github/workflows/deploy-service.yaml | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/deploy-service.yaml diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml new file mode 100644 index 00000000..c7508679 --- /dev/null +++ b/.github/workflows/deploy-service.yaml @@ -0,0 +1,34 @@ +name: Deploy Service + +on: + workflow_call: + secrets: + GCP_CREDENTIALS: + description: "The JSON credentials used to access GCP." + required: true + +jobs: + deploy: + runs-on: ubuntu-latest + # if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' + environment: ${{ github.ref_name }} + steps: + - name: ๐Ÿ›ซ Checkout + uses: actions/checkout@v4 + + # https://mikefarah.gitbook.io/yq/ + - name: ๐Ÿ–Š๏ธ Configure App Deployment + uses: mikefarah/yq@master + with: + cmd: | + name=${{ github.repository }} + name=${name#"ocadotechnology/codeforelife-"} + + yq -i ' + .service = "${{ github.ref_name }}-$name" + ' app.yaml + + - name: ๐Ÿš€ Deploy App on GCloud + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main + with: + gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} From ac403d399914645ef2711ba8d49de5c73efe5f2f Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 15:19:36 +0100 Subject: [PATCH 12/28] reuse workflow --- .github/workflows/frontend.yaml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 3f05a500..324ca1c0 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -16,15 +16,6 @@ jobs: secrets: inherit deploy: - runs-on: ubuntu-latest needs: [test] - # if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' - environment: ${{ github.ref_name }} - steps: - - name: ๐Ÿ›ซ Checkout - uses: actions/checkout@v4 - - - name: ๐Ÿš€ Deploy App on GCloud - uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main - with: - gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} + uses: ocadotechnology/codeforlife-workspace/.github/workflows/deploy-service.yaml@configure_js_services # TODO: set to @main + secrets: inherit From 92ec51102cea78f451b4632b77de86e2000d74be Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 15:47:30 +0100 Subject: [PATCH 13/28] set name correctly --- .github/workflows/deploy-service.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml index c7508679..37e18eb6 100644 --- a/.github/workflows/deploy-service.yaml +++ b/.github/workflows/deploy-service.yaml @@ -21,12 +21,16 @@ jobs: uses: mikefarah/yq@master with: cmd: | - name=${{ github.repository }} - name=${name#"ocadotechnology/codeforelife-"} + yq -i $( + # Set name with convention "{ENV_NAME}-{REPO_NAME}" + export name=${{ github.repository }} + name=${name#"ocadotechnology/codeforelife-"} + name="${{ github.ref_name }}-${name}" - yq -i ' - .service = "${{ github.ref_name }}-$name" - ' app.yaml + echo ' + .service = "${name}" + ' | envsubst + ) app.yaml - name: ๐Ÿš€ Deploy App on GCloud uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main From 089b06d760b49410ac83923c44d2fbacebf37bff Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 15:50:44 +0100 Subject: [PATCH 14/28] echo --- .github/workflows/deploy-service.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml index 37e18eb6..c68fc6ff 100644 --- a/.github/workflows/deploy-service.yaml +++ b/.github/workflows/deploy-service.yaml @@ -16,6 +16,19 @@ jobs: - name: ๐Ÿ›ซ Checkout uses: actions/checkout@v4 + - name: echo + run: | + echo $( + # Set name with convention "{ENV_NAME}-{REPO_NAME}" + export name=${{ github.repository }} + name=${name#"ocadotechnology/codeforelife-"} + name="${{ github.ref_name }}-${name}" + + echo ' + .service = "${name}" + ' | envsubst + ) + # https://mikefarah.gitbook.io/yq/ - name: ๐Ÿ–Š๏ธ Configure App Deployment uses: mikefarah/yq@master From 6db8a7a06613da8d2f3762c2cbccfac30119d5b6 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 15:56:38 +0100 Subject: [PATCH 15/28] fix typo --- .github/workflows/deploy-service.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml index c68fc6ff..9ad3cb2a 100644 --- a/.github/workflows/deploy-service.yaml +++ b/.github/workflows/deploy-service.yaml @@ -21,7 +21,7 @@ jobs: echo $( # Set name with convention "{ENV_NAME}-{REPO_NAME}" export name=${{ github.repository }} - name=${name#"ocadotechnology/codeforelife-"} + name=${name#"ocadotechnology/codeforlife-"} name="${{ github.ref_name }}-${name}" echo ' @@ -37,7 +37,7 @@ jobs: yq -i $( # Set name with convention "{ENV_NAME}-{REPO_NAME}" export name=${{ github.repository }} - name=${name#"ocadotechnology/codeforelife-"} + name=${name#"ocadotechnology/codeforlife-"} name="${{ github.ref_name }}-${name}" echo ' From 5f450f9b0af6e9c25623648d8e1a9394a6b22530 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 16:01:42 +0100 Subject: [PATCH 16/28] cat app.yaml --- .github/workflows/deploy-service.yaml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml index 9ad3cb2a..035f0d3c 100644 --- a/.github/workflows/deploy-service.yaml +++ b/.github/workflows/deploy-service.yaml @@ -16,19 +16,6 @@ jobs: - name: ๐Ÿ›ซ Checkout uses: actions/checkout@v4 - - name: echo - run: | - echo $( - # Set name with convention "{ENV_NAME}-{REPO_NAME}" - export name=${{ github.repository }} - name=${name#"ocadotechnology/codeforlife-"} - name="${{ github.ref_name }}-${name}" - - echo ' - .service = "${name}" - ' | envsubst - ) - # https://mikefarah.gitbook.io/yq/ - name: ๐Ÿ–Š๏ธ Configure App Deployment uses: mikefarah/yq@master @@ -45,6 +32,9 @@ jobs: ' | envsubst ) app.yaml + - name: cat app yaml + run: cat app.yaml + - name: ๐Ÿš€ Deploy App on GCloud uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main with: From 1efe26a69054b4fd070171ca862d19c41105f5b7 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 16:17:07 +0100 Subject: [PATCH 17/28] fix yq cmd --- .github/workflows/deploy-service.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml index 035f0d3c..18f3cd8d 100644 --- a/.github/workflows/deploy-service.yaml +++ b/.github/workflows/deploy-service.yaml @@ -21,7 +21,7 @@ jobs: uses: mikefarah/yq@master with: cmd: | - yq -i $( + config=$( # Set name with convention "{ENV_NAME}-{REPO_NAME}" export name=${{ github.repository }} name=${name#"ocadotechnology/codeforlife-"} @@ -30,7 +30,9 @@ jobs: echo ' .service = "${name}" ' | envsubst - ) app.yaml + ) + + yq -i "$config" app.yaml - name: cat app yaml run: cat app.yaml From c510205589b2395f698716fdb3eb30611c541947 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 16:36:10 +0100 Subject: [PATCH 18/28] fix yq query --- .github/workflows/deploy-service.yaml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml index 18f3cd8d..e601d5f0 100644 --- a/.github/workflows/deploy-service.yaml +++ b/.github/workflows/deploy-service.yaml @@ -21,18 +21,14 @@ jobs: uses: mikefarah/yq@master with: cmd: | - config=$( - # Set name with convention "{ENV_NAME}-{REPO_NAME}" - export name=${{ github.repository }} - name=${name#"ocadotechnology/codeforlife-"} - name="${{ github.ref_name }}-${name}" + # Set name with convention "{ENV_NAME}-{REPO_NAME}" + name=${{ github.repository }} + name=${name#"ocadotechnology/codeforlife-"} + name="${{ github.ref_name }}-${name}" - echo ' - .service = "${name}" - ' | envsubst - ) - - yq -i "$config" app.yaml + yq -i ' + .service = "'$name'" + ' app.yaml - name: cat app yaml run: cat app.yaml From a9aa899d67df0920372ae9eca7c81926b7010a2a Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 16:57:22 +0100 Subject: [PATCH 19/28] build app --- .github/workflows/deploy-service.yaml | 39 --------------------------- .github/workflows/frontend.yaml | 39 +++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 41 deletions(-) delete mode 100644 .github/workflows/deploy-service.yaml diff --git a/.github/workflows/deploy-service.yaml b/.github/workflows/deploy-service.yaml deleted file mode 100644 index e601d5f0..00000000 --- a/.github/workflows/deploy-service.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Deploy Service - -on: - workflow_call: - secrets: - GCP_CREDENTIALS: - description: "The JSON credentials used to access GCP." - required: true - -jobs: - deploy: - runs-on: ubuntu-latest - # if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' - environment: ${{ github.ref_name }} - steps: - - name: ๐Ÿ›ซ Checkout - uses: actions/checkout@v4 - - # https://mikefarah.gitbook.io/yq/ - - name: ๐Ÿ–Š๏ธ Configure App Deployment - uses: mikefarah/yq@master - with: - cmd: | - # Set name with convention "{ENV_NAME}-{REPO_NAME}" - name=${{ github.repository }} - name=${name#"ocadotechnology/codeforlife-"} - name="${{ github.ref_name }}-${name}" - - yq -i ' - .service = "'$name'" - ' app.yaml - - - name: cat app yaml - run: cat app.yaml - - - name: ๐Ÿš€ Deploy App on GCloud - uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main - with: - gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 324ca1c0..cba340a8 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -2,6 +2,12 @@ name: Frontend on: workflow_call: + inputs: + node-version: + description: "The Node.js version to set up." + type: number + required: false + default: 18 secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." @@ -16,6 +22,35 @@ jobs: secrets: inherit deploy: + runs-on: ubuntu-latest needs: [test] - uses: ocadotechnology/codeforlife-workspace/.github/workflows/deploy-service.yaml@configure_js_services # TODO: set to @main - secrets: inherit + # if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' + environment: ${{ github.ref_name }} + steps: + - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment + uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@configure_js_services # TODO: set to @main + with: + node-version: ${{ inputs.node-version }} + install-args: --production=false + + - name: ๐Ÿ—๏ธ Build App + run: yarn build + + # https://mikefarah.gitbook.io/yq/ + - name: ๐Ÿ–Š๏ธ Configure App Deployment + uses: mikefarah/yq@master + with: + cmd: | + # Set name with convention "{ENV_NAME}-{REPO_NAME}" + name=${{ github.repository }} + name=${name#"ocadotechnology/codeforlife-"} + name="${{ github.ref_name }}-${name}" + + yq -i ' + .service = "'$name'" + ' app.yaml + + - name: ๐Ÿš€ Deploy App on GCloud + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main + with: + gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} From d3db90d55008513ab4dec1648cc717671868130f Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 22:28:37 +0100 Subject: [PATCH 20/28] remove build step --- .github/workflows/frontend.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index cba340a8..0087f680 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -33,9 +33,6 @@ jobs: node-version: ${{ inputs.node-version }} install-args: --production=false - - name: ๐Ÿ—๏ธ Build App - run: yarn build - # https://mikefarah.gitbook.io/yq/ - name: ๐Ÿ–Š๏ธ Configure App Deployment uses: mikefarah/yq@master From b408acc98290b3c3143a35c5d2cdb237a7baa4fd Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 22:34:43 +0100 Subject: [PATCH 21/28] put build step back --- .github/workflows/frontend.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 0087f680..cba340a8 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -33,6 +33,9 @@ jobs: node-version: ${{ inputs.node-version }} install-args: --production=false + - name: ๐Ÿ—๏ธ Build App + run: yarn build + # https://mikefarah.gitbook.io/yq/ - name: ๐Ÿ–Š๏ธ Configure App Deployment uses: mikefarah/yq@master From 1532e379d60a7c91650be15a4e58a09db98e390d Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 24 May 2024 23:01:43 +0100 Subject: [PATCH 22/28] small fixes --- .github/workflows/frontend.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index cba340a8..dc3ea62a 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -24,7 +24,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: [test] - # if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' + if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' environment: ${{ github.ref_name }} steps: - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment @@ -47,6 +47,7 @@ jobs: name="${{ github.ref_name }}-${name}" yq -i ' + .runtime = "nodejs${{ inputs.node-version }}" | .service = "'$name'" ' app.yaml From bdf589317c4a5c16cbd61947931f30b6f77f2a74 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 28 May 2024 11:26:40 +0100 Subject: [PATCH 23/28] Backend workflow --- .github/workflows/backend.yaml | 81 +++++++++++++++++++++ .github/workflows/frontend.yaml | 9 ++- .github/workflows/test-javascript-code.yaml | 2 +- .github/workflows/test-python-code.yaml | 2 +- 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/backend.yaml diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml new file mode 100644 index 00000000..0aff66d2 --- /dev/null +++ b/.github/workflows/backend.yaml @@ -0,0 +1,81 @@ +name: Backend + +on: + workflow_call: + inputs: + python-version: + description: "The Python version to set up." + type: number + required: false + default: 3.8 + secrets: + CODECOV_TOKEN: + description: "The token used to gain access to Codecov." + required: false + GCP_CREDENTIALS: + description: "The JSON credentials used to access GCP." + required: false + +jobs: + test: + uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main + secrets: inherit + with: + python-version: ${{ inputs.python-version }} + + deploy: + runs-on: ubuntu-latest + needs: [test] + # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. + if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') + environment: ${{ github.ref_name }} + steps: + - name: ๐Ÿ Set up Python ${{ inputs.python-version }} Environment + uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main + with: + python-version: ${{ inputs.python-version }} + install-args: --dev + + - name: ๐Ÿ—๏ธ Generate requirements.txt + run: pipenv requirements > requirements.txt + + - name: ๐Ÿ—๏ธ Collect Static Files + run: pipenv run python ./manage.py collectstatic --noinput --clear + + # https://mikefarah.gitbook.io/yq/ + # TODO: clean up app.yaml environment variables + - name: ๐Ÿ–Š๏ธ Configure App Deployment + uses: mikefarah/yq@master + with: + cmd: | + # Set name with convention "{ENV_NAME}-{REPO_NAME}" + name=${{ github.repository }} + name=${name#"ocadotechnology/codeforlife-"} + name="${{ github.ref_name }}-${name}" + + # Check if service is the client-facing service. + is_root=$( + if [ ${{ github.ref_name }} == "production" ] + then echo "1" + else echo "0" + fi + ) + + # Set runtime with convention "python{PY_VERSION}". + # The version must have the dot removed: "python3.8" -> "python38". + runtime=python${{ inputs.python-version }} + runtime=${runtime//.} + + yq -i ' + .runtime = "'$runtime'" | + .service = "'$name'" | + .env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" | + .env_variables.SERVICE_NAME = "$name" | + .env_variables.SERVICE_IS_ROOT = "$is_root" | + .env_variables.MODULE_NAME = "${{ github.ref_name }}" + ' app.yaml + + - name: ๐Ÿš€ Deploy App on GCloud + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main + with: + gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index dc3ea62a..cf5558f8 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -11,20 +11,23 @@ on: secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." - required: true + required: false GCP_CREDENTIALS: description: "The JSON credentials used to access GCP." - required: true + required: false jobs: test: uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@configure_js_services # TODO: set to @main secrets: inherit + with: + node-version: ${{ inputs.node-version }} deploy: runs-on: ubuntu-latest needs: [test] - if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging' + # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. + if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') environment: ${{ github.ref_name }} steps: - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml index e81c7bba..7d546c7a 100644 --- a/.github/workflows/test-javascript-code.yaml +++ b/.github/workflows/test-javascript-code.yaml @@ -31,7 +31,7 @@ on: secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." - required: true + required: false # Needs to be false to support contributors jobs: test-js-code: diff --git a/.github/workflows/test-python-code.yaml b/.github/workflows/test-python-code.yaml index 784cf973..65b0595a 100644 --- a/.github/workflows/test-python-code.yaml +++ b/.github/workflows/test-python-code.yaml @@ -41,7 +41,7 @@ on: secrets: CODECOV_TOKEN: description: "The token used to gain access to Codecov." - required: true + required: false # Needs to be false to support contributors jobs: test-py-code: From b342d9b1e09641fc523d6d96ba35984da2bc9c54 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 28 May 2024 11:36:05 +0100 Subject: [PATCH 24/28] reuse action --- .github/workflows/cron.yaml | 17 ++++++----------- .github/workflows/dispatch.yaml | 17 ++++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/.github/workflows/cron.yaml b/.github/workflows/cron.yaml index 65daaf47..b3d2f712 100644 --- a/.github/workflows/cron.yaml +++ b/.github/workflows/cron.yaml @@ -5,7 +5,7 @@ on: branches: - main paths: - - 'cron.yaml' + - "cron.yaml" workflow_dispatch: jobs: @@ -13,15 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - name: ๐Ÿ›ซ Checkout - uses: actions/checkout@v3 - - - name: ๐Ÿ— Authenticate with GCloud - uses: google-github-actions/auth@v1 - with: - credentials_json: ${{ secrets.GCP_CREDENTIALS }} - - - name: ๐Ÿค– Set up GCloud SDK - uses: google-github-actions/setup-gcloud@v1 + uses: actions/checkout@v4 - name: ๐Ÿš€ Deploy Cron Jobs on GCloud - run: gcloud app deploy cron.yaml + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main + with: + gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} + deploy-args: cron.yaml diff --git a/.github/workflows/dispatch.yaml b/.github/workflows/dispatch.yaml index 4adf4f84..b867f47c 100644 --- a/.github/workflows/dispatch.yaml +++ b/.github/workflows/dispatch.yaml @@ -5,7 +5,7 @@ on: branches: - main paths: - - 'dispatch.yaml' + - "dispatch.yaml" workflow_dispatch: jobs: @@ -13,15 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - name: ๐Ÿ›ซ Checkout - uses: actions/checkout@v3 - - - name: ๐Ÿ— Authenticate with GCloud - uses: google-github-actions/auth@v1 - with: - credentials_json: ${{ secrets.GCP_CREDENTIALS }} - - - name: ๐Ÿค– Set up GCloud SDK - uses: google-github-actions/setup-gcloud@v1 + uses: actions/checkout@v4 - name: ๐Ÿš€ Deploy Routing Rules on GCloud - run: gcloud app deploy dispatch.yaml + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main + with: + gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} + deploy-args: dispatch.yaml From 32f7d29396b5cb7d90fbc0f1e02daea42939eef5 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 28 May 2024 12:23:24 +0100 Subject: [PATCH 25/28] only produce coverage if running within ocado tech --- .github/workflows/test-javascript-code.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml index 7d546c7a..2df73b3f 100644 --- a/.github/workflows/test-javascript-code.yaml +++ b/.github/workflows/test-javascript-code.yaml @@ -60,7 +60,13 @@ jobs: - name: ๐Ÿงช Test Code Units working-directory: ${{ inputs.working-directory }} - run: yarn test:coverage + run: | + if [ ${{ github.repository_owner_id }} = ${{ env.OCADO_TECH_ORG_ID }} ] + then + yarn test:coverage + else + yarn test:verbose + fi - name: ๐Ÿ“ˆ Upload Coverage Reports to Codecov if: github.repository_owner_id == env.OCADO_TECH_ORG_ID From c648ed0926592fe6efb413ea8afb04a149b8b728 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 28 May 2024 13:26:48 +0100 Subject: [PATCH 26/28] validate pr refs --- .github/workflows/frontend.yaml | 4 ++++ .github/workflows/validate-pull-request-refs.yaml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index cf5558f8..1788a2ba 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -17,8 +17,12 @@ on: required: false jobs: + validate-pr-refs: + uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@configure_js_services # TODO: set to @main + test: uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@configure_js_services # TODO: set to @main + needs: [validate-pr-refs] secrets: inherit with: node-version: ${{ inputs.node-version }} diff --git a/.github/workflows/validate-pull-request-refs.yaml b/.github/workflows/validate-pull-request-refs.yaml index eba8077a..35799424 100644 --- a/.github/workflows/validate-pull-request-refs.yaml +++ b/.github/workflows/validate-pull-request-refs.yaml @@ -6,6 +6,8 @@ on: jobs: validate-pr-refs: runs-on: ubuntu-latest + # If the repo's owner is Ocado Tech. and the triggering event is a pull request. + if: github.repository_owner_id == 2088731 && github.event_name == 'pull_request' env: PROD_REF: production STAGING_REF: staging From 6b92d52674721ef358a818a43e142b9b2e0fe38b Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 28 May 2024 13:31:38 +0100 Subject: [PATCH 27/28] independent jobs --- .github/workflows/frontend.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 1788a2ba..3e560fd8 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -22,14 +22,13 @@ jobs: test: uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@configure_js_services # TODO: set to @main - needs: [validate-pr-refs] secrets: inherit with: node-version: ${{ inputs.node-version }} deploy: runs-on: ubuntu-latest - needs: [test] + needs: [validate-pr-refs, test] # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') environment: ${{ github.ref_name }} From cabab0740e3947994aba69520aae7a32fdf32581 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 28 May 2024 13:35:41 +0100 Subject: [PATCH 28/28] use main branch --- .github/workflows/backend.yaml | 7 +++++-- .github/workflows/frontend.yaml | 8 ++++---- .github/workflows/test-javascript-code.yaml | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 0aff66d2..566eff1a 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -17,6 +17,9 @@ on: required: false jobs: + validate-pr-refs: + uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@main + test: uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main secrets: inherit @@ -25,7 +28,7 @@ jobs: deploy: runs-on: ubuntu-latest - needs: [test] + needs: [validate-pr-refs, test] # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') environment: ${{ github.ref_name }} @@ -76,6 +79,6 @@ jobs: ' app.yaml - name: ๐Ÿš€ Deploy App on GCloud - uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main with: gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 3e560fd8..ae9d4314 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -18,10 +18,10 @@ on: jobs: validate-pr-refs: - uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@configure_js_services # TODO: set to @main + uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@main test: - uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@configure_js_services # TODO: set to @main + uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@main secrets: inherit with: node-version: ${{ inputs.node-version }} @@ -34,7 +34,7 @@ jobs: environment: ${{ github.ref_name }} steps: - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment - uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@configure_js_services # TODO: set to @main + uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@main with: node-version: ${{ inputs.node-version }} install-args: --production=false @@ -58,6 +58,6 @@ jobs: ' app.yaml - name: ๐Ÿš€ Deploy App on GCloud - uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@configure_js_services # TODO: set to @main + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main with: gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} diff --git a/.github/workflows/test-javascript-code.yaml b/.github/workflows/test-javascript-code.yaml index 2df73b3f..f1e94331 100644 --- a/.github/workflows/test-javascript-code.yaml +++ b/.github/workflows/test-javascript-code.yaml @@ -40,7 +40,7 @@ jobs: OCADO_TECH_ORG_ID: 2088731 steps: - name: ๐ŸŒ Set up JavaScript ${{ inputs.node-version }} Environment - uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@configure_js_services # TODO: set to @main + uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@main with: node-version: ${{ inputs.node-version }} working-directory: ${{ inputs.working-directory }}