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-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
2023-04-14 09:47:41 +00:00
- edited
2023-01-20 10:21:22 +00:00
- synchronize
jobs :
2023-04-14 09:47:41 +00:00
node-modules :
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
lint-pr-title :
needs : node-modules
2023-07-13 09:19:37 +00:00
if : ${{ github.event_name == 'pull_request' }}
2023-04-14 09:47:41 +00:00
name : Verify PR title
uses : ./.github/workflows/lint-pr.yml
secrets : inherit
2023-04-03 13:53:50 +00:00
lint-test-build :
2023-05-02 17:41:21 +00:00
timeout-minutes : 60
2023-04-14 09:47:41 +00:00
needs : node-modules
2023-04-03 13:53:50 +00:00
runs-on : ubuntu-22.04
name : '(CI) lint + unit test + build'
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-04-03 13:53:50 +00:00
- name : Check formatting
run : yarn nx format:check
2023-03-29 13:20:49 +00:00
2023-04-03 13:53:50 +00:00
- name : Lint affected
run : yarn nx affected:lint --max-warnings=0
- name : Build affected spec
run : yarn nx affected --target=build-spec
2023-03-29 13:20:49 +00:00
2023-04-03 13:53:50 +00:00
- name : Test affected
run : yarn nx affected:test
- name : Build affected
2023-04-17 09:24:53 +00:00
run : yarn nx affected:build || (yarn install && yarn nx affected:build)
2023-04-03 13:53:50 +00:00
# See affected apps
2023-03-31 15:01:19 +00:00
- name : See affected apps
run : |
2023-05-22 09:16:33 +00:00
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 )"
2023-04-03 13:53:50 +00:00
echo ">>>> debug"
echo "NX_BASE: ${{ env.NX_BASE }}"
echo "NX_HEAD: ${{ env.NX_HEAD }}"
2023-05-22 09:16:33 +00:00
echo "Affected: ${affected}"
echo "Branch slug: ${branch_slug}"
2023-04-03 13:53:50 +00:00
echo ">>>> eof debug"
2023-06-28 12:54:25 +00:00
projects_array=()
2023-04-26 10:45:02 +00:00
preview_governance="not deployed"
preview_trading="not deployed"
preview_explorer="not deployed"
2023-06-06 11:47:42 +00:00
preview_tools="not deployed"
2023-06-28 12:54:25 +00:00
# parse if affected is any of three main applications, if none - use all of them
2023-06-06 12:29:46 +00:00
if echo "$affected" | grep -q governance; then
echo "Governance is affected"
2023-06-28 12:54:25 +00:00
projects_array+=("governance")
2023-05-22 09:16:33 +00:00
preview_governance=$(printf "https://%s.%s.vega.rocks" "governance" "$branch_slug")
fi
2023-06-06 12:29:46 +00:00
if echo "$affected" | grep -q trading; then
echo "Trading is affected"
2023-06-28 12:54:25 +00:00
projects_array+=("trading")
2023-05-22 09:16:33 +00:00
preview_trading=$(printf "https://%s.%s.vega.rocks" "trading" "$branch_slug")
fi
2023-06-06 12:29:46 +00:00
if echo "$affected" | grep -q explorer; then
echo "Explorer is affected"
2023-06-28 12:54:25 +00:00
projects_array+=("explorer")
2023-05-22 09:16:33 +00:00
preview_explorer=$(printf "https://%s.%s.vega.rocks" "explorer" "$branch_slug")
fi
2023-06-28 12:54:25 +00:00
if [[ ${#projects_array[@]} -eq 0 ]]; then
projects_array=("governance" "trading" "explorer")
2023-04-26 10:45:02 +00:00
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
2023-06-28 12:54:25 +00:00
# applications parsed before this loop are applicable for running e2e-tests
projects_e2e_array=()
for project in "${projects_array[@]}"; do
projects_e2e_array+=("${project}-e2e")
done
# all applications below this loop are not applicable for running e2e-test
# check if pull request event to deploy tools
2023-06-13 11:29:05 +00:00
if [[ "${{ github.event_name }}" = "pull_request" ]]; then
if echo "$affected" | grep -q multisig-signer; then
echo "Tools are affected"
2023-06-06 12:39:28 +00:00
echo "Deploying tools on preview"
2023-06-06 11:47:42 +00:00
preview_tools=$(printf "https://%s.%s.vega.rocks" "tools" "$branch_slug")
2023-06-28 12:54:25 +00:00
projects_array+=("multisig-signer")
2023-06-06 11:47:42 +00:00
fi
2023-06-28 12:54:25 +00:00
# those apps deploy only from develop to mainnet
2023-06-13 11:29:05 +00:00
elif [[ "${{ github.ref }}" =~ .*develop$ ]]; then
if echo "$affected" | grep -q multisig-signer; then
echo "Tools are affected"
2023-06-06 12:39:28 +00:00
echo "Deploying tools on s3"
2023-06-28 12:54:25 +00:00
projects_array+=("multisig-signer")
2023-06-06 12:39:28 +00:00
fi
2023-06-13 11:29:05 +00:00
if echo "$affected" | grep -q static; then
2023-06-14 10:37:41 +00:00
echo "static is affected"
2023-06-13 11:29:05 +00:00
echo "Deploying static on s3"
2023-06-28 12:54:25 +00:00
projects_array+=("static")
2023-06-13 11:29:05 +00:00
fi
2023-06-14 10:37:41 +00:00
if echo "$affected" | grep -q ui-toolkit; then
echo "ui-toolkit is affected"
echo "Deploying ui-toolkit on s3"
2023-06-28 12:54:25 +00:00
projects_array+=("ui-toolkit")
2023-06-14 10:37:41 +00:00
fi
2023-06-06 11:47:42 +00:00
fi
2023-06-13 11:29:05 +00:00
2023-07-12 15:37:49 +00:00
# if branch starts with release/ and ends with trading / governance or explorer - overwrite the array of affected projects with fixed single application
if [[ "${{ github.ref }}" == release* ]]; then
case "${{ github.ref }}" in
2023-07-12 15:47:46 +00:00
*trading)
projects_array=(trading)
projects_e2e_array=(trading)
;;
*governance)
projects_array=(governance)
projects_e2e_array=(governance)
;;
*explorer)
projects_array=(explorer)
projects_e2e_array=(explorer)
;;
esac
2023-07-12 15:37:49 +00:00
fi
2023-06-28 12:54:25 +00:00
echo "Projects: ${projects_array[@]}"
echo "Projects E2E: ${projects_e2e_array[@]}"
projects_json=$(jq -M --compact-output --null-input '$ARGS.positional' --args -- "${projects_array[@]}")
projects_e2e_json=$(jq -M --compact-output --null-input '$ARGS.positional' --args -- "${projects_e2e_array[@]}")
echo PROJECTS_E2E=$projects_e2e_json >> $GITHUB_ENV
echo PROJECTS=$projects_json >> $GITHUB_ENV
2023-04-26 10:45:02 +00:00
echo PREVIEW_GOVERNANCE=$preview_governance >> $GITHUB_ENV
echo PREVIEW_TRADING=$preview_trading >> $GITHUB_ENV
echo PREVIEW_EXPLORER=$preview_explorer >> $GITHUB_ENV
2023-06-06 11:47:42 +00:00
echo PREVIEW_TOOLS=$preview_tools >> $GITHUB_ENV
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-04-03 13:53:50 +00:00
cypress :
needs : lint-test-build
name : '(CI) cypress'
2023-06-28 13:09:17 +00:00
# if: ${{ needs.lint-test-build.outputs.projects-e2e != '[]' }}
2023-01-20 10:21:22 +00:00
uses : ./.github/workflows/cypress-run.yml
secrets : inherit
with :
2023-04-03 13:53:50 +00:00
projects : ${{ needs.lint-test-build.outputs.projects-e2e }}
2023-01-20 10:21:22 +00:00
tags : '@smoke @regression'
2023-04-03 13:53:50 +00:00
publish-dist :
needs : lint-test-build
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-04-03 13:53:50 +00:00
projects : ${{ needs.lint-test-build.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
- lint-test-build
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:]\+&@#/%=~_|]'
if [[ "${{ needs.lint-test-build.outputs.preview_governance }}" =~ $regex ]]; then
2023-07-10 13:53:38 +00:00
until curl --insecure --location --fail "${{ needs.lint-test-build.outputs.preview_governance }}"; do
echo "waiting for governance preview: ${{ needs.lint-test-build.outputs.preview_governance }}"
2023-05-25 12:36:38 +00:00
sleep 5
done
fi
if [[ "${{ needs.lint-test-build.outputs.preview_explorer }}" =~ $regex ]]; then
2023-07-10 13:53:38 +00:00
until curl --insecure --location --fail "${{ needs.lint-test-build.outputs.preview_explorer }}"; do
echo "waiting for explorer preview: ${{ needs.lint-test-build.outputs.preview_explorer }}"
2023-05-25 12:36:38 +00:00
sleep 5
done
fi
if [[ "${{ needs.lint-test-build.outputs.preview_trading }}" =~ $regex ]]; then
2023-07-10 13:53:38 +00:00
until curl --insecure --location --fail "${{ needs.lint-test-build.outputs.preview_trading }}"; do
echo "waiting for trading preview: ${{ needs.lint-test-build.outputs.preview_trading }}"
2023-05-25 12:36:38 +00:00
sleep 5
done
fi
2023-06-06 11:47:42 +00:00
if [[ "${{ needs.lint-test-build.outputs.preview_tools }}" =~ $regex ]]; then
2023-07-10 13:53:38 +00:00
until curl --insecure --location --fail "${{ needs.lint-test-build.outputs.preview_tools }}"; do
echo "waiting for tools preview: ${{ needs.lint-test-build.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-04-26 10:45:02 +00:00
* governance : ${{ needs.lint-test-build.outputs.preview_governance }}
* explorer : ${{ needs.lint-test-build.outputs.preview_explorer }}
* trading : ${{ needs.lint-test-build.outputs.preview_trading }}
2023-06-06 11:47:42 +00:00
* tools : ${{ needs.lint-test-build.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