-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from ocadotechnology/configure_js_services
add prettier
- Loading branch information
Showing
12 changed files
with
430 additions
and
106 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 used 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 }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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: | ||
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 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
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 }} | ||
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@main | ||
with: | ||
gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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." | ||
required: false | ||
GCP_CREDENTIALS: | ||
description: "The JSON credentials used to access GCP." | ||
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-javascript-code.yaml@main | ||
secrets: inherit | ||
with: | ||
node-version: ${{ inputs.node-version }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
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 }} | ||
steps: | ||
- name: 🌐 Set up JavaScript ${{ inputs.node-version }} Environment | ||
uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@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 ' | ||
.runtime = "nodejs${{ inputs.node-version }}" | | ||
.service = "'$name'" | ||
' app.yaml | ||
- name: 🚀 Deploy App on GCloud | ||
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/deploy-app@main | ||
with: | ||
gcp-credentials: ${{ secrets.GCP_CREDENTIALS }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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" | ||
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." | ||
required: false # Needs to be false to support contributors | ||
|
||
jobs: | ||
test-js-code: | ||
runs-on: ubuntu-latest | ||
env: | ||
OCADO_TECH_ORG_ID: 2088731 | ||
steps: | ||
- name: 🌐 Set up JavaScript ${{ inputs.node-version }} Environment | ||
uses: ocadotechnology/codeforlife-workspace/.github/actions/javascript/setup-environment@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 | ||
|
||
- name: 🧪 Test Code Units | ||
working-directory: ${{ inputs.working-directory }} | ||
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 | ||
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: ${{ inputs.codecov-file }} |
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
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
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
Oops, something went wrong.