name: CI/CD on: push: branches: - release/* - develop tags: - v* pull_request: types: - opened - ready_for_review - reopened - edited - synchronize jobs: node-modules: runs-on: ubuntu-22.04 name: 'Cache yarn modules' steps: - name: Checkout uses: actions/checkout@v3 - name: Cache node modules id: cache uses: actions/cache@v3 with: path: node_modules key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }} # comment out "restore-keys" if you need to rebuild yarn from 0 restore-keys: | ${{ runner.os }}-cache-node-modules- - name: Setup node uses: actions/setup-node@v3 if: steps.cache.outputs.cache-hit != 'true' with: node-version-file: '.nvmrc' # https://stackoverflow.com/questions/61010294/how-to-cache-yarn-packages-in-github-actions cache: yarn - name: yarn install if: steps.cache.outputs.cache-hit != 'true' run: yarn install --pure-lockfile lint-pr-title: needs: node-modules if: ${{ github.event_name == 'pull_request' }} name: Verify PR title uses: ./.github/workflows/lint-pr.yml secrets: inherit lint-test-build: timeout-minutes: 60 needs: node-modules runs-on: ubuntu-22.04 name: '(CI) lint + unit test + build' steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup node uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' # https://stackoverflow.com/questions/61010294/how-to-cache-yarn-packages-in-github-actions cache: yarn - name: Cache node modules uses: actions/cache@v3 with: path: node_modules key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }} - name: Derive appropriate SHAs for base and head for `nx affected` commands uses: nrwl/nx-set-shas@v3 with: main-branch-name: develop - name: Check formatting run: yarn nx format:check - name: Lint affected run: yarn nx affected:lint --max-warnings=0 - name: Build affected spec run: yarn nx affected --target=build-spec - name: Test affected run: yarn nx affected:test - name: Build affected run: yarn nx affected:build || (yarn install && yarn nx affected:build) # See affected apps - name: See affected apps run: | affected="$(yarn nx print-affected --base=${{ env.NX_BASE }} --head=${{ env.NX_HEAD }} --select=projects)" branch_slug="$(echo '${{ github.head_ref || github.ref_name }}' | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | cut -c 1-50 )" echo ">>>> debug" echo "NX_BASE: ${{ env.NX_BASE }}" echo "NX_HEAD: ${{ env.NX_HEAD }}" echo "Affected: ${affected}" echo "Branch slug: ${branch_slug}" echo ">>>> eof debug" projects_e2e="" preview_governance="not deployed" preview_trading="not deployed" preview_explorer="not deployed" if [[ $affected == *"governance"* ]]; then projects_e2e+='"governance-e2e" ' preview_governance=$(printf "https://%s.%s.vega.rocks" "governance" "$branch_slug") fi if [[ $affected == *"trading"* ]]; then projects_e2e+='"trading-e2e" ' preview_trading=$(printf "https://%s.%s.vega.rocks" "trading" "$branch_slug") fi if [[ $affected == *"explorer"* ]]; then projects_e2e+='"explorer-e2e" ' preview_explorer=$(printf "https://%s.%s.vega.rocks" "explorer" "$branch_slug") fi if [[ -z "$projects_e2e" ]]; then projects_e2e+='"governance-e2e" "trading-e2e" "explorer-e2e" ' preview_governance=$(printf "https://%s.%s.vega.rocks" "governance" "$branch_slug") preview_trading=$(printf "https://%s.%s.vega.rocks" "trading" "$branch_slug") preview_explorer=$(printf "https://%s.%s.vega.rocks" "explorer" "$branch_slug") fi projects_e2e=${projects_e2e%?} projects_e2e=[${projects_e2e// /,}] echo PROJECTS_E2E=$projects_e2e >> $GITHUB_ENV echo PROJECTS=$(echo $projects_e2e | sed 's|-e2e||g') >> $GITHUB_ENV echo PREVIEW_GOVERNANCE=$preview_governance >> $GITHUB_ENV echo PREVIEW_TRADING=$preview_trading >> $GITHUB_ENV echo PREVIEW_EXPLORER=$preview_explorer >> $GITHUB_ENV outputs: projects: ${{ env.PROJECTS }} projects-e2e: ${{ env.PROJECTS_E2E }} preview_governance: ${{ env.PREVIEW_GOVERNANCE }} preview_trading: ${{ env.PREVIEW_TRADING }} preview_explorer: ${{ env.PREVIEW_EXPLORER }} cypress: needs: lint-test-build name: '(CI) cypress' if: ${{ needs.lint-test-build.outputs.projects != '[]' }} uses: ./.github/workflows/cypress-run.yml secrets: inherit with: projects: ${{ needs.lint-test-build.outputs.projects-e2e }} tags: '@smoke @regression' publish-dist: needs: lint-test-build name: '(CD) publish dist' if: ${{ needs.lint-test-build.outputs.projects != '[]' }} uses: ./.github/workflows/publish-dist.yml secrets: inherit with: projects: ${{ needs.lint-test-build.outputs.projects }} dist-check: runs-on: ubuntu-latest needs: - publish-dist - lint-test-build if: ${{ github.event_name == 'pull_request' }} name: '(CD) comment preview links' steps: - name: Find Comment uses: peter-evans/find-comment@v2 id: fc with: issue-number: ${{ github.event.pull_request.number }} body-includes: Previews - name: Create comment uses: peter-evans/create-or-update-comment@v3 if: ${{ steps.fc.outputs.comment-id == 0 }} with: issue-number: ${{ github.event.pull_request.number }} body: | Previews: * governance: ${{ needs.lint-test-build.outputs.preview_governance }} * explorer: ${{ needs.lint-test-build.outputs.preview_explorer }} * trading: ${{ needs.lint-test-build.outputs.preview_trading }} cypress-check: name: '(CI) cypress - check' runs-on: ubuntu-latest needs: cypress steps: - run: echo Done! # Report single result at the end, to avoid mess with required checks in PR cypress-result: if: ${{ always() }} needs: cypress runs-on: ubuntu-22.04 steps: - run: | result="${{ needs.cypress.result }}" if [[ $result == "success" || $result == "skipped" ]]; then exit 0 else exit 1 fi