diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml new file mode 100644 index 0000000..560aeee --- /dev/null +++ b/.github/workflows/dependencies.yml @@ -0,0 +1,85 @@ +name: Dependency reusable workflow + +on: + workflow_call: + inputs: + node_version: + required: false + default: '18.x' + type: string + with-front-dependencies-installation: + type: boolean + default: false + with-build_mails: + type: boolean + default: false + +jobs: + front-dependencies-installation: + if: ${{ inputs.with-front-dependencies-installation == true }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore the frontend cache + uses: actions/cache@v4 + id: front-node_modules + with: + path: "src/frontend/**/node_modules" + key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + - name: Setup Node.js + if: steps.front-node_modules.outputs.cache-hit != 'true' + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + - name: Install dependencies + if: steps.front-node_modules.outputs.cache-hit != 'true' + run: cd src/frontend/ && yarn install --frozen-lockfile + - name: Cache install frontend + if: steps.front-node_modules.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: "src/frontend/**/node_modules" + key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + + build-mails: + if: ${{ inputs.with-build_mails == true }} + runs-on: ubuntu-latest + defaults: + run: + working-directory: src/mail + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Restore the mail templates + uses: actions/cache@v4 + id: mail-templates + with: + path: "src/backend/core/templates/mail" + key: mail-templates-${{ hashFiles('src/mail/mjml') }} + + - name: Setup Node.js + if: steps.mail-templates.outputs.cache-hit != 'true' + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + + - name: Install yarn + if: steps.mail-templates.outputs.cache-hit != 'true' + run: npm install -g yarn + + - name: Install node dependencies + if: steps.mail-templates.outputs.cache-hit != 'true' + run: yarn install --frozen-lockfile + + - name: Build mails + if: steps.mail-templates.outputs.cache-hit != 'true' + run: yarn build + + - name: Cache mail templates + if: steps.mail-templates.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: "src/backend/core/templates/mail" + key: mail-templates-${{ hashFiles('src/mail/mjml') }} diff --git a/.github/workflows/people.yml b/.github/workflows/people.yml index b6ebd8e..487658a 100644 --- a/.github/workflows/people.yml +++ b/.github/workflows/people.yml @@ -9,6 +9,14 @@ on: - '*' jobs: + # Call the reusable workflow to install dependencies + dependencies: + uses: ./.github/workflows/dependencies.yml + with: + node_version: '18.x' + with-front-dependencies-installation: true + with-build_mails: true + lint-git: runs-on: ubuntu-latest if: github.event_name == 'pull_request' # Makes sense only for pull requests @@ -56,39 +64,9 @@ jobs: exit 1 fi - install-front: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '18.x' - - - name: Restore the frontend cache - uses: actions/cache@v4 - id: front-node_modules - with: - path: 'src/frontend/**/node_modules' - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} - - - name: Install dependencies - if: steps.front-node_modules.outputs.cache-hit != 'true' - run: cd src/frontend/ && yarn install --frozen-lockfile - - - name: Cache install frontend - if: steps.front-node_modules.outputs.cache-hit != 'true' - uses: actions/cache@v4 - with: - path: 'src/frontend/**/node_modules' - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} - build-front: runs-on: ubuntu-latest - needs: install-front + needs: dependencies steps: - name: Checkout repository uses: actions/checkout@v4 @@ -111,7 +89,7 @@ jobs: test-front: runs-on: ubuntu-latest - needs: install-front + needs: dependencies steps: - name: Checkout repository uses: actions/checkout@v4 @@ -128,7 +106,7 @@ jobs: lint-front: runs-on: ubuntu-latest - needs: install-front + needs: dependencies steps: - name: Checkout repository uses: actions/checkout@v4 @@ -145,7 +123,7 @@ jobs: test-e2e: runs-on: ubuntu-latest - needs: [build-mails, build-front] + needs: [dependencies, build-front] timeout-minutes: 10 strategy: fail-fast: false @@ -161,11 +139,13 @@ jobs: make create-env-files cat env.d/development/common.e2e.dist >> env.d/development/common - - name: Download mails' templates - uses: actions/download-artifact@v4 + - name: Restore the mail templates + uses: actions/cache@v4 + id: mail-templates with: - name: mails-templates - path: src/backend/core/templates/mail + path: "src/backend/core/templates/mail" + key: mail-templates-${{ hashFiles('src/mail/mjml') }} + fail-on-cache-miss: true - name: Restore the frontend cache uses: actions/cache@v4 @@ -231,30 +211,6 @@ jobs: if: ${{ contains(needs.*.result, 'failure') }} run: exit 1 - build-mails: - runs-on: ubuntu-latest - defaults: - run: - working-directory: src/mail - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - name: Install yarn - run: npm install -g yarn - - name: Install node dependencies - run: yarn install --frozen-lockfile - - name: Build mails - run: yarn build - - name: Persist mails' templates - uses: actions/upload-artifact@v4 - with: - name: mails-templates - path: src/backend/core/templates/mail - lint-back: runs-on: ubuntu-latest defaults: @@ -278,7 +234,7 @@ jobs: test-back: runs-on: ubuntu-latest - needs: build-mails + needs: dependencies defaults: run: working-directory: src/backend @@ -313,11 +269,13 @@ jobs: run: | sudo mkdir -p /data/media && \ sudo mkdir -p /data/static - - name: Download mails' templates - uses: actions/download-artifact@v4 + - name: Restore the mail templates + uses: actions/cache@v4 + id: mail-templates with: - name: mails-templates - path: src/backend/core/templates/mail + path: "src/backend/core/templates/mail" + key: mail-templates-${{ hashFiles('src/mail/mjml') }} + fail-on-cache-miss: true - name: Install Python uses: actions/setup-python@v5 with: