fix(app): 3731 - Ne pas planter en cas d'échec au fetch du nombre de … #21
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: Test and deploy CI | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref_name }} | |
cancel-in-progress: true | |
env: | |
CI_ENV_NAME: ci | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
registry: ${{ steps.registry.outputs.registry }} | |
build_matrix: ${{ steps.config.outputs.build }} | |
deploy_matrix: ${{ steps.config.outputs.deploy }} | |
test_matrix: ${{ steps.config.outputs.test }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
fetch-depth: 0 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.17" | |
- name: Get registry | |
id: registry | |
working-directory: devops/scripts | |
env: | |
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} | |
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }} | |
run: | | |
registry=$(node get-environment-registry.js ${{ env.CI_ENV_NAME }}) | |
echo "registry: $registry" | |
echo "registry=$registry" >> $GITHUB_OUTPUT | |
- name: Get matrices configuration | |
id: config | |
run: | | |
# BUILD MATRIX | |
echo "[]" \ | |
| jq '. + [{name:"api", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- api packages/lib package-lock.json | cut -d " " -f 1)" \ | |
| jq '. + [{name:"apiv2", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- apiv2 packages/lib package-lock.json | cut -d " " -f 1)" \ | |
| jq '. + [{name:"app", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- app packages package-lock.json | cut -d " " -f 1)" \ | |
| jq '. + [{name:"admin", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- admin packages package-lock.json | cut -d " " -f 1)" > build.json | |
echo "Build matrix" | |
cat build.json | |
echo "build=$(jq -c < build.json)" >> $GITHUB_OUTPUT | |
# DEPLOY MATRIX | |
cat build.json \ | |
| jq '. + [{name:"tasks", tag:.[]|select(.name == "api")|.tag}]' \ | |
| jq '. + [{name:"tasksv2", tag:.[]|select(.name == "apiv2")|.tag}]' > deploy.json | |
echo "Deploy matrix" | |
cat deploy.json | |
echo "deploy=$(jq -c < deploy.json)" >> $GITHUB_OUTPUT | |
# TEST MATRIX | |
echo "[]" \ | |
| jq '. + [{name:"api"}]' \ | |
| jq '. + [{name:"apiv2"}]' \ | |
| jq '. + [{name:"app"}]' \ | |
| jq '. + [{name:"admin"}]' \ | |
| jq '. + [{name:"lib"}]' > test.json | |
echo "Test matrix" | |
cat test.json | |
echo "test=$(jq -c < test.json)" >> $GITHUB_OUTPUT | |
test: | |
needs: prepare | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app: ${{ fromJSON(needs.prepare.outputs.test_matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Run tests | |
uses: jenseng/dynamic-uses@v1 | |
with: | |
uses: ./.github/actions/run-tests-${{matrix.app.name}} | |
with: '{"branch_name": "${{ github.ref_name }}", "CC_TEST_REPORTER_ID": "${{ secrets.CC_TEST_REPORTER_ID }}" }' | |
build: | |
needs: [prepare, test] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app: ${{ fromJSON(needs.prepare.outputs.build_matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Login to Docker Container Registry | |
uses: docker/login-action@v2 | |
with: | |
username: nologin | |
password: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }} | |
registry: ${{ needs.prepare.outputs.registry }} | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.17" | |
- name: Build image | |
working-directory: devops/scripts | |
env: | |
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} | |
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }} | |
run: | | |
node build-application-docker.js --push ${{ env.CI_ENV_NAME }} ${{matrix.app.name}} ${{matrix.app.tag}} | |
deploy: | |
needs: [prepare, build] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app: ${{ fromJSON(needs.prepare.outputs.deploy_matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.17" | |
- name: Deploy image on Scaleway | |
working-directory: devops/scripts | |
env: | |
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} | |
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }} | |
run: | | |
node deploy-scaleway.js ${{ env.CI_ENV_NAME }} ${{matrix.app.name}} ${{matrix.app.tag}} |