2023-04-03 13:53:50 +00:00
|
|
|
name: CI/CD
|
2023-01-20 10:21:22 +00:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
2023-04-03 13:53:50 +00:00
|
|
|
- release/*
|
2023-04-12 07:38:26 +00:00
|
|
|
- develop
|
2023-10-02 12:29:59 +00:00
|
|
|
- main
|
2023-07-13 09:19:37 +00:00
|
|
|
pull_request:
|
2023-01-20 10:21:22 +00:00
|
|
|
types:
|
|
|
|
- opened
|
2023-04-14 09:47:41 +00:00
|
|
|
- ready_for_review
|
2023-01-20 10:21:22 +00:00
|
|
|
- reopened
|
|
|
|
- synchronize
|
|
|
|
jobs:
|
2023-04-14 09:47:41 +00:00
|
|
|
node-modules:
|
2023-09-20 18:13:43 +00:00
|
|
|
# All jobs depend on node_modules, so none should run if the PR is in draft
|
|
|
|
if: github.event.pull_request.draft == false
|
2023-04-14 09:47:41 +00:00
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
name: 'Cache yarn modules'
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v3
|
2023-06-27 09:18:13 +00:00
|
|
|
with:
|
|
|
|
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
2023-04-14 09:47:41 +00:00
|
|
|
- name: Cache node modules
|
|
|
|
id: cache
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
|
2023-04-20 11:56:33 +00:00
|
|
|
# comment out "restore-keys" if you need to rebuild yarn from 0
|
2023-04-14 09:47:41 +00:00
|
|
|
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
|
|
|
|
|
2023-09-06 20:35:49 +00:00
|
|
|
lint-format:
|
|
|
|
timeout-minutes: 20
|
2023-04-14 09:47:41 +00:00
|
|
|
needs: node-modules
|
2023-04-03 13:53:50 +00:00
|
|
|
runs-on: ubuntu-22.04
|
2023-09-06 20:35:49 +00:00
|
|
|
name: '(CI) lint + format check'
|
2023-01-20 10:21:22 +00:00
|
|
|
steps:
|
2023-03-31 15:01:19 +00:00
|
|
|
- name: Checkout
|
2023-01-20 10:21:22 +00:00
|
|
|
uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2023-06-27 09:18:13 +00:00
|
|
|
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
2023-01-20 10:21:22 +00:00
|
|
|
|
|
|
|
- name: Setup node
|
|
|
|
uses: actions/setup-node@v3
|
2023-03-24 15:42:33 +00:00
|
|
|
with:
|
2023-04-03 13:53:50 +00:00
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
# https://stackoverflow.com/questions/61010294/how-to-cache-yarn-packages-in-github-actions
|
|
|
|
cache: yarn
|
|
|
|
|
2023-04-14 09:47:41 +00:00
|
|
|
- name: Cache node modules
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
|
2023-01-20 10:21:22 +00:00
|
|
|
|
|
|
|
- name: Derive appropriate SHAs for base and head for `nx affected` commands
|
2023-03-29 13:20:49 +00:00
|
|
|
uses: nrwl/nx-set-shas@v3
|
2023-01-20 10:21:22 +00:00
|
|
|
with:
|
2023-03-29 13:20:49 +00:00
|
|
|
main-branch-name: develop
|
2023-01-20 10:21:22 +00:00
|
|
|
|
2023-09-06 20:35:49 +00:00
|
|
|
- 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
|
|
|
|
|
|
|
|
test-affected:
|
|
|
|
timeout-minutes: 30
|
|
|
|
needs: build-sources
|
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
name: 'run unit test of affected apps'
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
|
|
|
|
|
|
- name: Setup node
|
|
|
|
uses: actions/setup-node@v3
|
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
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: Test affected
|
|
|
|
run: yarn nx affected:test
|
|
|
|
|
|
|
|
build-sources:
|
|
|
|
timeout-minutes: 30
|
|
|
|
needs: lint-format
|
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
name: 'Build sources of affected apps'
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
|
|
|
|
|
|
- name: Setup node
|
|
|
|
uses: actions/setup-node@v3
|
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
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
|
|
|
|
|
2023-07-26 14:08:57 +00:00
|
|
|
# See affected apps
|
|
|
|
- name: See affected apps
|
|
|
|
run: |
|
|
|
|
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 )"
|
|
|
|
python3 tools/ci/check-affected.py --github-ref="${{ github.ref }}" --branch-slug="$branch_slug" --event-name="${{ github.event_name }}"
|
|
|
|
|
|
|
|
- name: Verify script result
|
|
|
|
run: |
|
|
|
|
echo "Check outputs from script"
|
|
|
|
echo "projects: ${{ env.PROJECTS }}"
|
|
|
|
echo "projects-e2e: ${{ env.PROJECTS_E2E }}"
|
|
|
|
echo "preview_governance: ${{ env.PREVIEW_GOVERNANCE }}"
|
|
|
|
echo "preview_trading: ${{ env.PREVIEW_TRADING }}"
|
|
|
|
echo "preview_explorer: ${{ env.PREVIEW_EXPLORER }}"
|
|
|
|
echo "preview_tools: ${{ env.PREVIEW_TOOLS }}"
|
|
|
|
|
2023-04-03 13:53:50 +00:00
|
|
|
- name: Build affected
|
2023-04-17 09:24:53 +00:00
|
|
|
run: yarn nx affected:build || (yarn install && yarn nx affected:build)
|
2023-01-20 10:21:22 +00:00
|
|
|
outputs:
|
|
|
|
projects: ${{ env.PROJECTS }}
|
2023-03-24 15:42:33 +00:00
|
|
|
projects-e2e: ${{ env.PROJECTS_E2E }}
|
2023-04-26 10:45:02 +00:00
|
|
|
preview_governance: ${{ env.PREVIEW_GOVERNANCE }}
|
|
|
|
preview_trading: ${{ env.PREVIEW_TRADING }}
|
|
|
|
preview_explorer: ${{ env.PREVIEW_EXPLORER }}
|
2023-06-06 11:47:42 +00:00
|
|
|
preview_tools: ${{ env.PREVIEW_TOOLS }}
|
2023-01-20 10:21:22 +00:00
|
|
|
|
2023-10-02 12:29:59 +00:00
|
|
|
check-e2e-needed:
|
|
|
|
runs-on: ubuntu-latest
|
2023-09-06 20:35:49 +00:00
|
|
|
needs: build-sources
|
2023-10-02 12:29:59 +00:00
|
|
|
name: '(CI) check if e2e needed'
|
|
|
|
outputs:
|
|
|
|
run-tests: ${{ steps.check-test.outputs.e2e-needed }}
|
|
|
|
steps:
|
|
|
|
- name: Check branch
|
|
|
|
id: check-test
|
|
|
|
run: |
|
2023-10-03 11:57:17 +00:00
|
|
|
if [[ "${{ github.base_ref }}" == "develop" ]]; then
|
2023-10-02 12:29:59 +00:00
|
|
|
echo "e2e-needed=true" >> $GITHUB_OUTPUT
|
2023-10-03 11:57:17 +00:00
|
|
|
elif [[ "${{ github.base_ref }}" == "main" ]]; then
|
2023-10-02 12:29:59 +00:00
|
|
|
echo "e2e-needed=true" >> $GITHUB_OUTPUT
|
2023-10-03 11:57:17 +00:00
|
|
|
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref_name }}" == *"release/"* ]]; then
|
2023-10-02 12:29:59 +00:00
|
|
|
echo "e2e-needed=true" >> $GITHUB_OUTPUT
|
|
|
|
else
|
|
|
|
echo "e2e-needed=false" >> $GITHUB_OUTPUT
|
|
|
|
fi
|
|
|
|
- name: Print result
|
|
|
|
run: |
|
|
|
|
echo "e2e-needed: ${{ steps.check-test.outputs.e2e-needed }}"
|
|
|
|
|
|
|
|
cypress:
|
|
|
|
needs: [build-sources, check-e2e-needed]
|
2023-04-03 13:53:50 +00:00
|
|
|
name: '(CI) cypress'
|
2023-10-02 12:29:59 +00:00
|
|
|
if: ${{ needs.check-e2e-needed.outputs.run-tests == 'true' }}
|
2023-01-20 10:21:22 +00:00
|
|
|
uses: ./.github/workflows/cypress-run.yml
|
|
|
|
secrets: inherit
|
|
|
|
with:
|
2023-09-06 20:35:49 +00:00
|
|
|
projects: ${{ needs.build-sources.outputs.projects-e2e }}
|
2023-08-15 11:26:13 +00:00
|
|
|
tags: '@smoke'
|
2023-01-20 10:21:22 +00:00
|
|
|
|
2023-10-06 14:12:13 +00:00
|
|
|
console-e2e:
|
|
|
|
needs: [build-sources, check-e2e-needed]
|
|
|
|
name: '(CI) console python'
|
|
|
|
uses: ./.github/workflows/console-test-run.yml
|
|
|
|
secrets: inherit
|
2023-10-09 15:24:18 +00:00
|
|
|
if: needs.check-e2e-needed.outputs.run-tests == 'true' && contains(needs.build-sources.outputs.projects, 'trading')
|
2023-10-06 14:12:13 +00:00
|
|
|
with:
|
|
|
|
github-sha: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
|
|
|
2023-04-03 13:53:50 +00:00
|
|
|
publish-dist:
|
2023-09-06 20:35:49 +00:00
|
|
|
needs: build-sources
|
2023-04-03 13:53:50 +00:00
|
|
|
name: '(CD) publish dist'
|
2023-07-13 09:19:37 +00:00
|
|
|
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'vegaprotocol/frontend-monorepo') || github.event_name == 'push' }}
|
2023-04-03 13:53:50 +00:00
|
|
|
uses: ./.github/workflows/publish-dist.yml
|
2023-03-24 15:42:33 +00:00
|
|
|
secrets: inherit
|
|
|
|
with:
|
2023-09-06 20:35:49 +00:00
|
|
|
projects: ${{ needs.build-sources.outputs.projects }}
|
2023-03-24 15:42:33 +00:00
|
|
|
|
2023-04-14 09:47:41 +00:00
|
|
|
dist-check:
|
|
|
|
runs-on: ubuntu-latest
|
2023-04-26 10:45:02 +00:00
|
|
|
needs:
|
|
|
|
- publish-dist
|
2023-09-06 20:35:49 +00:00
|
|
|
- build-sources
|
2023-07-13 09:19:37 +00:00
|
|
|
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'vegaprotocol/frontend-monorepo' }}
|
2023-05-25 12:36:38 +00:00
|
|
|
timeout-minutes: 60
|
2023-04-14 09:47:41 +00:00
|
|
|
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
|
|
|
|
|
2023-05-25 12:36:38 +00:00
|
|
|
- name: Wait for deployments
|
|
|
|
run: |
|
|
|
|
# https://stackoverflow.com/questions/3183444/check-for-valid-link-url
|
|
|
|
regex='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]'
|
2023-09-06 20:35:49 +00:00
|
|
|
if [[ "${{ needs.build-sources.outputs.preview_governance }}" =~ $regex ]]; then
|
|
|
|
until curl --insecure --location --fail "${{ needs.build-sources.outputs.preview_governance }}"; do
|
|
|
|
echo "waiting for governance preview: ${{ needs.build-sources.outputs.preview_governance }}"
|
2023-05-25 12:36:38 +00:00
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
fi
|
2023-09-06 20:35:49 +00:00
|
|
|
if [[ "${{ needs.build-sources.outputs.preview_explorer }}" =~ $regex ]]; then
|
|
|
|
until curl --insecure --location --fail "${{ needs.build-sources.outputs.preview_explorer }}"; do
|
|
|
|
echo "waiting for explorer preview: ${{ needs.build-sources.outputs.preview_explorer }}"
|
2023-05-25 12:36:38 +00:00
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
fi
|
2023-09-06 20:35:49 +00:00
|
|
|
if [[ "${{ needs.build-sources.outputs.preview_trading }}" =~ $regex ]]; then
|
|
|
|
until curl --insecure --location --fail "${{ needs.build-sources.outputs.preview_trading }}"; do
|
|
|
|
echo "waiting for trading preview: ${{ needs.build-sources.outputs.preview_trading }}"
|
2023-05-25 12:36:38 +00:00
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
fi
|
2023-09-06 20:35:49 +00:00
|
|
|
if [[ "${{ needs.build-sources.outputs.preview_tools }}" =~ $regex ]]; then
|
|
|
|
until curl --insecure --location --fail "${{ needs.build-sources.outputs.preview_tools }}"; do
|
|
|
|
echo "waiting for tools preview: ${{ needs.build-sources.outputs.preview_tools }}"
|
2023-06-06 11:47:42 +00:00
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
fi
|
2023-05-25 12:36:38 +00:00
|
|
|
|
2023-04-14 09:47:41 +00:00
|
|
|
- name: Create comment
|
|
|
|
uses: peter-evans/create-or-update-comment@v3
|
2023-04-26 10:45:02 +00:00
|
|
|
if: ${{ steps.fc.outputs.comment-id == 0 }}
|
2023-04-14 09:47:41 +00:00
|
|
|
with:
|
|
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
|
|
body: |
|
2023-07-13 09:19:37 +00:00
|
|
|
Previews
|
2023-09-06 20:35:49 +00:00
|
|
|
* governance: ${{ needs.build-sources.outputs.preview_governance }}
|
|
|
|
* explorer: ${{ needs.build-sources.outputs.preview_explorer }}
|
|
|
|
* trading: ${{ needs.build-sources.outputs.preview_trading }}
|
|
|
|
* tools: ${{ needs.build-sources.outputs.preview_tools }}
|
2023-04-14 09:47:41 +00:00
|
|
|
|
2023-05-25 12:36:38 +00:00
|
|
|
# Report single result at the end, to avoid mess with required checks in PR
|
2023-04-14 09:47:41 +00:00
|
|
|
cypress-check:
|
|
|
|
name: '(CI) cypress - check'
|
2023-01-20 10:21:22 +00:00
|
|
|
if: ${{ always() }}
|
2023-04-03 13:53:50 +00:00
|
|
|
needs: cypress
|
|
|
|
runs-on: ubuntu-22.04
|
2023-01-20 10:21:22 +00:00
|
|
|
steps:
|
|
|
|
- run: |
|
2023-04-03 13:53:50 +00:00
|
|
|
result="${{ needs.cypress.result }}"
|
2023-01-20 10:21:22 +00:00
|
|
|
if [[ $result == "success" || $result == "skipped" ]]; then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|