Skip to content

Commit 70537cd

Browse files
authored
Merge pull request #108 from ocadotechnology/configure_js_services
add prettier
2 parents c63c25b + cabab07 commit 70537cd

File tree

12 files changed

+430
-106
lines changed

12 files changed

+430
-106
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Code for Life - GCloud - Deploy App"
2+
description: "Deploy an app to Google Cloud."
3+
inputs:
4+
gcp-credentials:
5+
description: "The JSON credentials used to access GCP."
6+
required: true
7+
deploy-args:
8+
description: "Arguments to pass to `gcloud app deploy`."
9+
required: false
10+
runs:
11+
using: composite
12+
steps:
13+
- name: 🗝 Authenticate with GCloud
14+
uses: google-github-actions/auth@v2
15+
with:
16+
credentials_json: ${{ inputs.gcp-credentials }}
17+
18+
- name: 🤖 Set up GCloud SDK
19+
uses: google-github-actions/setup-gcloud@v2
20+
21+
- name: 🚀 Deploy App on GCloud
22+
shell: bash
23+
run: gcloud app deploy ${{ inputs.deploy-args }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "Code for Life - JavaScript - Setup Environment"
2+
description: "Set up a JavaScript environment."
3+
inputs:
4+
checkout:
5+
description: "A flag to designate if the code should be checked out."
6+
required: true
7+
default: "true"
8+
node-version:
9+
description: "The Node.js version to set up."
10+
required: true
11+
default: "18"
12+
working-directory:
13+
description: "The current working directory."
14+
required: true
15+
default: "."
16+
install-args:
17+
description: "Arguments to pass to pipenv install."
18+
required: false
19+
runs:
20+
using: composite
21+
steps:
22+
- name: 🛫 Checkout
23+
if: ${{ inputs.checkout == 'true' }}
24+
uses: actions/checkout@v4
25+
26+
- name: 🌐 Set up Node
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: ${{ inputs.node-version }}
30+
31+
- name: ⬆️ Upgrade npm
32+
shell: bash
33+
run: npm install --global npm
34+
35+
- name: 🛠 Install Yarn
36+
shell: bash
37+
run: npm install --global yarn
38+
39+
- name: 🛠 Install Dependencies
40+
shell: bash
41+
working-directory: ${{ inputs.working-directory }}
42+
run: yarn install ${{ inputs.install-args }}

.github/workflows/backend.yaml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Backend
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
python-version:
7+
description: "The Python version to set up."
8+
type: number
9+
required: false
10+
default: 3.8
11+
secrets:
12+
CODECOV_TOKEN:
13+
description: "The token used to gain access to Codecov."
14+
required: false
15+
GCP_CREDENTIALS:
16+
description: "The JSON credentials used to access GCP."
17+
required: false
18+
19+
jobs:
20+
validate-pr-refs:
21+
uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@main
22+
23+
test:
24+
uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main
25+
secrets: inherit
26+
with:
27+
python-version: ${{ inputs.python-version }}
28+
29+
deploy:
30+
runs-on: ubuntu-latest
31+
needs: [validate-pr-refs, test]
32+
# Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch.
33+
if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging')
34+
environment: ${{ github.ref_name }}
35+
steps:
36+
- name: 🐍 Set up Python ${{ inputs.python-version }} Environment
37+
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main
38+
with:
39+
python-version: ${{ inputs.python-version }}
40+
install-args: --dev
41+
42+
- name: 🏗️ Generate requirements.txt
43+
run: pipenv requirements > requirements.txt
44+
45+
- name: 🏗️ Collect Static Files
46+
run: pipenv run python ./manage.py collectstatic --noinput --clear
47+
48+
# https://mikefarah.gitbook.io/yq/
49+
# TODO: clean up app.yaml environment variables
50+
- name: 🖊️ Configure App Deployment
51+
uses: mikefarah/yq@master
52+
with:
53+
cmd: |
54+
# Set name with convention "{ENV_NAME}-{REPO_NAME}"
55+
name=${{ github.repository }}
56+
name=${name#"ocadotechnology/codeforlife-"}
57+
name="${{ github.ref_name }}-${name}"
58+
59+
# Check if service is the client-facing service.
60+
is_root=$(
61+
if [ ${{ github.ref_name }} == "production" ]
62+
then echo "1"
63+
else echo "0"
64+
fi
65+
)
66+
67+
# Set runtime with convention "python{PY_VERSION}".
68+
# The version must have the dot removed: "python3.8" -> "python38".
69+
runtime=python${{ inputs.python-version }}
70+
runtime=${runtime//.}
71+
72+
yq -i '
73+
.runtime = "'$runtime'" |
74+
.service = "'$name'" |
75+
.env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" |
76+
.env_variables.SERVICE_NAME = "$name" |
77+
.env_variables.SERVICE_IS_ROOT = "$is_root" |
78+
.env_variables.MODULE_NAME = "${{ github.ref_name }}"
79+
' app.yaml
80+
81+
- name: 🚀 Deploy App on GCloud
82+
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main
83+
with:
84+
gcp-credentials: ${{ secrets.GCP_CREDENTIALS }}

.github/workflows/cron.yaml

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@ on:
55
branches:
66
- main
77
paths:
8-
- 'cron.yaml'
8+
- "cron.yaml"
99
workflow_dispatch:
1010

1111
jobs:
1212
deploy:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: 🛫 Checkout
16-
uses: actions/checkout@v3
17-
18-
- name: 🗝 Authenticate with GCloud
19-
uses: google-github-actions/auth@v1
20-
with:
21-
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
22-
23-
- name: 🤖 Set up GCloud SDK
24-
uses: google-github-actions/setup-gcloud@v1
16+
uses: actions/checkout@v4
2517

2618
- name: 🚀 Deploy Cron Jobs on GCloud
27-
run: gcloud app deploy cron.yaml
19+
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main
20+
with:
21+
gcp-credentials: ${{ secrets.GCP_CREDENTIALS }}
22+
deploy-args: cron.yaml

.github/workflows/dispatch.yaml

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@ on:
55
branches:
66
- main
77
paths:
8-
- 'dispatch.yaml'
8+
- "dispatch.yaml"
99
workflow_dispatch:
1010

1111
jobs:
1212
deploy:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: 🛫 Checkout
16-
uses: actions/checkout@v3
17-
18-
- name: 🗝 Authenticate with GCloud
19-
uses: google-github-actions/auth@v1
20-
with:
21-
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
22-
23-
- name: 🤖 Set up GCloud SDK
24-
uses: google-github-actions/setup-gcloud@v1
16+
uses: actions/checkout@v4
2517

2618
- name: 🚀 Deploy Routing Rules on GCloud
27-
run: gcloud app deploy dispatch.yaml
19+
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main
20+
with:
21+
gcp-credentials: ${{ secrets.GCP_CREDENTIALS }}
22+
deploy-args: dispatch.yaml

.github/workflows/frontend.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Frontend
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node-version:
7+
description: "The Node.js version to set up."
8+
type: number
9+
required: false
10+
default: 18
11+
secrets:
12+
CODECOV_TOKEN:
13+
description: "The token used to gain access to Codecov."
14+
required: false
15+
GCP_CREDENTIALS:
16+
description: "The JSON credentials used to access GCP."
17+
required: false
18+
19+
jobs:
20+
validate-pr-refs:
21+
uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@main
22+
23+
test:
24+
uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-javascript-code.yaml@main
25+
secrets: inherit
26+
with:
27+
node-version: ${{ inputs.node-version }}
28+
29+
deploy:
30+
runs-on: ubuntu-latest
31+
needs: [validate-pr-refs, test]
32+
# Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch.
33+
if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging')
34+
environment: ${{ github.ref_name }}
35+
steps:
36+
- name: 🌐 Set up JavaScript ${{ inputs.node-version }} Environment
37+
uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@main
38+
with:
39+
node-version: ${{ inputs.node-version }}
40+
install-args: --production=false
41+
42+
- name: 🏗️ Build App
43+
run: yarn build
44+
45+
# https://mikefarah.gitbook.io/yq/
46+
- name: 🖊️ Configure App Deployment
47+
uses: mikefarah/yq@master
48+
with:
49+
cmd: |
50+
# Set name with convention "{ENV_NAME}-{REPO_NAME}"
51+
name=${{ github.repository }}
52+
name=${name#"ocadotechnology/codeforlife-"}
53+
name="${{ github.ref_name }}-${name}"
54+
55+
yq -i '
56+
.runtime = "nodejs${{ inputs.node-version }}" |
57+
.service = "'$name'"
58+
' app.yaml
59+
60+
- name: 🚀 Deploy App on GCloud
61+
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main
62+
with:
63+
gcp-credentials: ${{ secrets.GCP_CREDENTIALS }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Test JavaScript Code
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node-version:
7+
description: "The Node.js version to set up."
8+
type: number
9+
required: false
10+
default: 18
11+
working-directory:
12+
description: "The current working directory."
13+
type: string
14+
required: false
15+
default: "."
16+
codecov-slug:
17+
description: "The slug provided to Codecov for the coverage report."
18+
type: string
19+
required: false
20+
default: ${{ github.repository }}
21+
codecov-yml-path:
22+
description: "The path of the Codecov YAML file."
23+
type: string
24+
required: false
25+
default: "./codecov.yml"
26+
codecov-file:
27+
description: "The path to the coverage file to upload."
28+
type: string
29+
required: false
30+
default: "coverage/cobertura-coverage.xml"
31+
secrets:
32+
CODECOV_TOKEN:
33+
description: "The token used to gain access to Codecov."
34+
required: false # Needs to be false to support contributors
35+
36+
jobs:
37+
test-js-code:
38+
runs-on: ubuntu-latest
39+
env:
40+
OCADO_TECH_ORG_ID: 2088731
41+
steps:
42+
- name: 🌐 Set up JavaScript ${{ inputs.node-version }} Environment
43+
uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@main
44+
with:
45+
node-version: ${{ inputs.node-version }}
46+
working-directory: ${{ inputs.working-directory }}
47+
install-args: --production=false
48+
49+
- name: 🔎 Check Code Format
50+
working-directory: ${{ inputs.working-directory }}
51+
run: yarn format:check
52+
53+
- name: 🔎 Check Static Type Hints
54+
working-directory: ${{ inputs.working-directory }}
55+
run: yarn type-check
56+
57+
- name: 🔎 Check Static Code
58+
working-directory: ${{ inputs.working-directory }}
59+
run: yarn lint
60+
61+
- name: 🧪 Test Code Units
62+
working-directory: ${{ inputs.working-directory }}
63+
run: |
64+
if [ ${{ github.repository_owner_id }} = ${{ env.OCADO_TECH_ORG_ID }} ]
65+
then
66+
yarn test:coverage
67+
else
68+
yarn test:verbose
69+
fi
70+
71+
- name: 📈 Upload Coverage Reports to Codecov
72+
if: github.repository_owner_id == env.OCADO_TECH_ORG_ID
73+
uses: codecov/codecov-action@v4
74+
with:
75+
fail_ci_if_error: true
76+
token: ${{ secrets.CODECOV_TOKEN }}
77+
slug: ${{ inputs.codecov-slug }}
78+
codecov_yml_path: ${{ inputs.codecov-yml-path }}
79+
working-directory: ${{ inputs.working-directory }}
80+
file: ${{ inputs.codecov-file }}

.github/workflows/test-python-code.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ on:
4141
secrets:
4242
CODECOV_TOKEN:
4343
description: "The token used to gain access to Codecov."
44-
required: false
44+
required: false # Needs to be false to support contributors
4545

4646
jobs:
4747
test-py-code:

.github/workflows/validate-pull-request-refs.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
jobs:
77
validate-pr-refs:
88
runs-on: ubuntu-latest
9+
# If the repo's owner is Ocado Tech. and the triggering event is a pull request.
10+
if: github.repository_owner_id == 2088731 && github.event_name == 'pull_request'
911
env:
1012
PROD_REF: production
1113
STAGING_REF: staging

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525
[submodule "codeforlife-sso"]
2626
path = codeforlife-sso
2727
url = https://github.com/ocadotechnology/codeforlife-sso.git
28+
[submodule "codeforlife-portal-frontend"]
29+
path = codeforlife-portal-frontend
30+
url = https://github.com/ocadotechnology/codeforlife-portal-frontend.git

0 commit comments

Comments
 (0)