feat(openchallenges): added unit tests to the image service (#2291) #27
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: CI | |
on: | |
push: | |
branches: | |
- main | |
- 'renovate/**' | |
pull_request: | |
env: | |
NX_BRANCH: ${{ github.event.number }} | |
NX_RUN_GROUP: ${{ github.run_id }} | |
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }} | |
NX_CLOUD_ENCRYPTION_KEY: ${{ secrets.NX_CLOUD_ENCRYPTION_KEY }} | |
NX_CLOUD_ENV_NAME: 'linux' | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
DOCKER_USERNAME: ${{ github.actor }} | |
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
push: | |
runs-on: ubuntu-22.04-4core-16GBRAM-150GBSSD | |
if: ${{ github.event_name != 'pull_request' }} | |
# env: | |
# NX_BRANCH: main | |
steps: | |
- uses: actions/checkout@v3 | |
name: Checkout [${{ github.ref_name }}] | |
with: | |
fetch-depth: 0 | |
- name: Derive appropriate SHAs for base and head for `nx affected` commands | |
uses: nrwl/nx-set-shas@v3 | |
- name: Set up Yarn cache | |
uses: actions/cache@v3 | |
with: | |
path: '/tmp/.yarn/cache' | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Set up Renv cache | |
uses: actions/cache@v3 | |
with: | |
path: '/tmp/.cache/R/renv/cache' | |
key: ${{ runner.os }}-renv-cache-${{ hashFiles('**/renv.lock') }} | |
restore-keys: | | |
${{ runner.os }}-renv-cache- | |
- name: Set up Poetry cache | |
uses: actions/cache@v3 | |
with: | |
path: '/tmp/.cache/pypoetry' | |
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
- name: Set up venv cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/tmp/.local/share/virtualenv | |
**/.venv | |
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }} | |
- name: Set up Gradle cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/tmp/.gradle/caches | |
/tmp/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Install the Dev Container CLI | |
run: npm install -g @devcontainers/[email protected] | |
- name: Start the dev container | |
run: | | |
mkdir -p \ | |
/tmp/.yarn/cache \ | |
/tmp/.cache/R/renv/cache \ | |
/tmp/.cache/pypoetry \ | |
/tmp/.local/share/virtualenv \ | |
/tmp/.gradle/caches \ | |
/tmp/.gradle/wrapper | |
devcontainer up \ | |
--mount type=bind,source=/tmp/.yarn/cache,target=/workspaces/sage-monorepo/.yarn/cache \ | |
--mount type=bind,source=/tmp/.cache/R/renv/cache,target=/home/vscode/.cache/R/renv/cache \ | |
--mount type=bind,source=/tmp/.cache/pypoetry,target=/home/vscode/.cache/pypoetry \ | |
--mount type=bind,source=/tmp/.local/share/virtualenv,target=/home/vscode/.local/share/virtualenv \ | |
--mount type=bind,source=/tmp/.gradle/caches,target=/home/vscode/.gradle/caches \ | |
--mount type=bind,source=/tmp/.gradle/wrapper,target=/home/vscode/.gradle/wrapper \ | |
--workspace-folder ../sage-monorepo | |
- name: Prepare the workspace | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c " | |
sudo chown -R vscode:vscode \ | |
/workspaces/sage-monorepo \ | |
/home/vscode/.cache \ | |
/home/vscode/.local \ | |
/home/vscode/.gradle \ | |
&& . ./dev-env.sh \ | |
&& workspace-install-affected" | |
- name: Lint the affected projects | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx affected --target=lint" | |
- name: Build the affected projects | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx affected --target=build,server" | |
- name: Test the affected projects (unit) | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx affected --target=test" | |
- name: Test the affected projects (integration) | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx affected --target=integration-test" | |
- name: Scan the affected projects with Sonar | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx affected --target=sonar" | |
- name: Publishing the images of the SELECTED projects | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin ghcr.io \ | |
&& nx affected --target=publish-image" | |
- name: Remove the dev container | |
run: docker rm -f sage_devcontainer | |
pr: | |
runs-on: ubuntu-22.04-4core-16GBRAM-150GBSSD | |
# Runs this job if triggered by a PR and if at least one of these conditions are true: | |
# - the PR originate from a fork | |
# - the branch name does not start with `renovate/` since we know that the workflow would have | |
# been already triggered by the `push` event. | |
if: | | |
github.event_name == 'pull_request' | |
&& ( | |
github.event.pull_request.head.repo.full_name != | |
github.event.pull_request.base.repo.full_name | |
|| !startsWith(github.head_ref, 'renovate/') | |
) | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
fetch-depth: 0 | |
- name: Derive appropriate SHAs for base and head for `nx affected` commands | |
uses: nrwl/nx-set-shas@v3 | |
- name: Set up Yarn cache | |
uses: actions/cache@v3 | |
with: | |
path: '/tmp/.yarn/cache' | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Set up Renv cache | |
uses: actions/cache@v3 | |
with: | |
path: '/tmp/.cache/R/renv/cache' | |
key: ${{ runner.os }}-renv-cache-${{ hashFiles('**/renv.lock') }} | |
restore-keys: | | |
${{ runner.os }}-renv-cache- | |
- name: Set up Poetry cache | |
uses: actions/cache@v3 | |
with: | |
path: '/tmp/.cache/pypoetry' | |
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
- name: Set up venv cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/tmp/.local/share/virtualenv | |
**/.venv | |
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }} | |
- name: Set up Gradle cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/tmp/.gradle/caches | |
/tmp/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Install the Dev Container CLI | |
run: npm install -g @devcontainers/[email protected] | |
- name: Start the dev container | |
run: | | |
mkdir -p \ | |
/tmp/.yarn/cache \ | |
/tmp/.cache/R/renv/cache \ | |
/tmp/.cache/pypoetry \ | |
/tmp/.local/share/virtualenv \ | |
/tmp/.gradle/caches \ | |
/tmp/.gradle/wrapper | |
devcontainer up \ | |
--mount type=bind,source=/tmp/.yarn/cache,target=/workspaces/sage-monorepo/.yarn/cache \ | |
--mount type=bind,source=/tmp/.cache/R/renv/cache,target=/home/vscode/.cache/R/renv/cache \ | |
--mount type=bind,source=/tmp/.cache/pypoetry,target=/home/vscode/.cache/pypoetry \ | |
--mount type=bind,source=/tmp/.local/share/virtualenv,target=/home/vscode/.local/share/virtualenv \ | |
--mount type=bind,source=/tmp/.gradle/caches,target=/home/vscode/.gradle/caches \ | |
--mount type=bind,source=/tmp/.gradle/wrapper,target=/home/vscode/.gradle/wrapper \ | |
--workspace-folder ../sage-monorepo | |
- name: Prepare the workspace | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c " | |
sudo chown -R vscode:vscode \ | |
/workspaces/sage-monorepo \ | |
/home/vscode/.cache \ | |
/home/vscode/.local \ | |
/home/vscode/.gradle \ | |
&& . ./dev-env.sh \ | |
&& workspace-install" | |
- name: Lint the affected projects | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx run-many --target=lint" | |
- name: Build the affected projects | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx run-many --target=build,server" | |
- name: Test the affected projects (unit) | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx run-many --target=test" | |
- name: Test the affected projects (integration) | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx run-many --target=integration-test" | |
- name: Building the images of the SELECTED projects | |
run: | | |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \ | |
&& nx affected --target=build-image" | |
- name: Remove the dev container | |
run: docker rm -f sage_devcontainer |