Cypress #11077
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: Cypress | |
on: | |
# allow running manually | |
workflow_dispatch: | |
pull_request: | |
branches: [ 'master', 'stable-*', 'feature/*' ] | |
push: | |
branches: [ 'master', 'stable-*', 'feature/*' ] | |
# daily on master | |
schedule: | |
- cron: '30 5 * * *' | |
concurrency: | |
group: cypress-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
cypress: | |
runs-on: ubuntu-latest | |
env: | |
# base of a PR, or pushed-to branch outside PRs, or master | |
BRANCH: ${{ github.base_ref || github.ref || 'refs/heads/master' }} | |
strategy: | |
fail-fast: false | |
matrix: | |
test: | |
- 'screenshots' | |
- 'approval' | |
- 'approval_modal' | |
- 'collections' | |
- 'community' | |
- 'ee_controller' | |
- 'execution_environments' | |
- 'groups_and_users' | |
- 'imports' | |
- 'insights' | |
- 'insights_collections' | |
- 'misc' | |
- 'namespaces' | |
- 'repo' | |
steps: | |
- name: "Install galaxykit dependency" | |
run: | | |
# pip install git+https://github.com/ansible/galaxykit.git@branch_name | |
pip install git+https://github.com/ansible/galaxykit.git | |
- name: "Set env.SHORT_BRANCH, BACKEND_FLAVOR" | |
run: | | |
SHORT_BRANCH=`sed 's/^refs\/heads\///' <<< $BRANCH` | |
case "${{ matrix.test }}" in | |
community*) | |
BACKEND_FLAVOR=community | |
echo "community" | |
;; | |
insights*) | |
BACKEND_FLAVOR=insights | |
echo "insights" | |
;; | |
*) | |
BACKEND_FLAVOR=standalone | |
echo "standalone" | |
;; | |
esac | |
echo "SHORT_BRANCH=${SHORT_BRANCH}" >> $GITHUB_ENV | |
echo "BACKEND_FLAVOR=${BACKEND_FLAVOR}" >> $GITHUB_ENV | |
echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV | |
- name: "Set variables for screenshots" | |
if: matrix.test == 'screenshots' | |
run: | | |
UI_COMMIT_MASTER=`curl -s https://api.github.com/repos/ansible/ansible-hub-ui/branches/${SHORT_BRANCH} | jq -r .commit.sha` | |
echo "UI_COMMIT_MASTER=${UI_COMMIT_MASTER}" >> $GITHUB_ENV | |
COMPARE_SCREENSHOTS=${{ github.event_name == 'pull_request' }} | |
echo 'compare screenshots:' | |
echo $COMPARE_SCREENSHOTS | |
echo "COMPARE_SCREENSHOTS=${COMPARE_SCREENSHOTS}" >> $GITHUB_ENV | |
- name: "Checkout ansible-hub-ui (${{ github.ref }})" | |
uses: actions/checkout@v3 | |
with: | |
path: 'ansible-hub-ui' | |
- name: "Checkout galaxy_ng (${{ env.SHORT_BRANCH }})" | |
uses: actions/checkout@v3 | |
with: | |
repository: 'ansible/galaxy_ng' | |
ref: '${{ env.SHORT_BRANCH }}' | |
path: 'galaxy_ng' | |
- name: "Checkout oci_env (main)" | |
uses: actions/checkout@v3 | |
with: | |
repository: 'pulp/oci_env' | |
path: 'oci_env' | |
- name: "Configure oci_env" | |
working-directory: 'oci_env' | |
run: | | |
pip install --editable ./client/ | |
# merge common, profile-specific and test matrix specific config | |
cat ../ansible-hub-ui/.github/workflows/cypress/compose.env.common \ | |
../ansible-hub-ui/.github/workflows/cypress/compose.env."$BACKEND_FLAVOR" \ | |
../ansible-hub-ui/test/cypress/e2e/"${{ matrix.test }}"/compose.env \ | |
| sed 's/^\s\+//' | tee compose.env || [ -s compose.env ] | |
- name: "oci-env compose build" | |
working-directory: 'oci_env' | |
run: 'oci-env compose build' | |
- name: "oci-env compose up" | |
working-directory: 'oci_env' | |
run: 'oci-env compose up &' | |
- name: "Install node 16" | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: "Cache ~/.npm & ~/.cache/Cypress" | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.npm | |
~/.cache/Cypress | |
key: npm-${{ env.SHORT_BRANCH }}-${{ hashFiles('ansible-hub-ui/**/package-lock.json') }} | |
restore-keys: | | |
npm-${{ env.SHORT_BRANCH }}- | |
npm- | |
- name: "Build standalone UI" | |
if: ${{ env.BACKEND_FLAVOR == 'standalone' }} | |
working-directory: 'ansible-hub-ui' | |
run: | | |
npm install | |
# production displays unknown translations literally, make sure it's up to date | |
npm run gettext:extract | |
npm run gettext:compile | |
npm run build-standalone | |
# save the App.*.js hash for later verification | |
BUILD_HASH=`ls dist/js/App*js | cut -d. -f2` | |
echo "BUILD_HASH=${BUILD_HASH}" >> $GITHUB_ENV | |
- name: "Build community UI" | |
if: ${{ env.BACKEND_FLAVOR == 'community' }} | |
working-directory: 'ansible-hub-ui' | |
run: | | |
npm install | |
# production displays unknown translations literally, make sure it's up to date | |
npm run gettext:extract | |
npm run gettext:compile | |
npm run build-community | |
# save the App.*.js hash for later verification | |
BUILD_HASH=`ls dist/js/App*js | cut -d. -f2` | |
echo "BUILD_HASH=${BUILD_HASH}" >> $GITHUB_ENV | |
- name: "Serve standalone UI" | |
if: ${{ env.BACKEND_FLAVOR == 'standalone' }} | |
run: | | |
mkdir -p www/static/ | |
mv ansible-hub-ui/dist www/static/galaxy_ng | |
cd www | |
echo '{}' > package.json | |
npm install local-web-server | |
node_modules/.bin/ws --port 8002 --directory . --spa static/galaxy_ng/index.html \ | |
--rewrite '/api/(.*) -> http://localhost:5001/api/$1' \ | |
--rewrite '/pulp/api/(.*) -> http://localhost:5001/pulp/api/$1' \ | |
--rewrite '/v2/(.*) -> http://localhost:5001/v2/$1' \ | |
--rewrite '/extensions/v2/(.*) -> http://localhost:5001/extensions/v2/$1' & | |
- name: "Serve community UI" | |
if: ${{ env.BACKEND_FLAVOR == 'community' }} | |
run: | | |
mkdir -p www/ | |
mv ansible-hub-ui/dist/* www/ | |
cd www | |
echo '{}' > package.json | |
npm install local-web-server | |
node_modules/.bin/ws --port 8002 --directory . --spa index.html \ | |
--rewrite '/api/(.*) -> http://localhost:5001/api/$1' \ | |
--rewrite '/pulp/api/(.*) -> http://localhost:5001/pulp/api/$1' \ | |
--rewrite '/v2/(.*) -> http://localhost:5001/v2/$1' \ | |
--rewrite '/extensions/v2/(.*) -> http://localhost:5001/extensions/v2/$1' & | |
- name: "Run insights UI" | |
if: ${{ env.BACKEND_FLAVOR == 'insights' }} | |
working-directory: 'ansible-hub-ui' | |
run: | | |
npm install | |
# production displays unknown translations literally, make sure it's up to date | |
npm run gettext:extract | |
npm run gettext:compile | |
# pre-pull containers (and check for version changes) | |
FROM=node_modules/@redhat-cloud-services/frontend-components-config-utilities/standalone/services/ | |
grep postgres:9.6 "$FROM"/rbac.js | |
docker pull postgres:9.6 | |
grep redis:5.0.4 "$FROM"/rbac.js | |
docker pull redis:5.0.4 | |
grep quay.io/cloudservices/rbac "$FROM"/rbac.js | |
docker pull quay.io/cloudservices/rbac | |
grep jboss/keycloak "$FROM"/default/chrome.js | |
docker pull jboss/keycloak | |
npm run start-insights & | |
- name: "Install Cypress & test dependencies" | |
working-directory: 'ansible-hub-ui/test' | |
run: | | |
npm install | |
- name: "Install Imagemagick" | |
if: matrix.test == 'screenshots' | |
run: | | |
sudo apt install imagemagick | |
- name: "Configure Cypress" | |
working-directory: 'ansible-hub-ui/test' | |
run: | | |
cp -aiv ../.github/workflows/cypress/cypress.env.json."$BACKEND_FLAVOR" cypress.env.json | |
- name: "Ensure standalone index.html uses the new js" | |
if: ${{ env.BACKEND_FLAVOR == 'standalone' }} | |
run: | | |
echo 'expecting /static/galaxy_ng/js/App.'"$BUILD_HASH"'.js' | |
curl http://localhost:8002/static/galaxy_ng/index.html | tee /dev/stderr | grep '/static/galaxy_ng/js/App.'"$BUILD_HASH"'.js' | |
- name: "Ensure community index.html uses the new js" | |
if: ${{ env.BACKEND_FLAVOR == 'community' }} | |
run: | | |
echo 'expecting /js/App.'"$BUILD_HASH"'.js' | |
curl http://localhost:8002/index.html | tee /dev/stderr | grep '/js/App.'"$BUILD_HASH"'.js' | |
- name: "Ensure insights is served" | |
if: ${{ env.BACKEND_FLAVOR == 'insights' }} | |
run: | | |
echo waiting for containers to start | |
sleep 30 | |
curl http://localhost:8002/preview/ansible/automation-hub/ | tee /dev/stderr | grep '/beta/apps/chrome/js/' | |
sleep 30 | |
- name: "Ensure galaxykit can connect to API (community)" | |
if: ${{ env.BACKEND_FLAVOR == 'community' }} | |
run: | | |
galaxykit -s http://localhost:8002/api/ -u admin -p admin collection list | |
- name: "Ensure galaxykit can connect to API (standalone)" | |
if: ${{ env.BACKEND_FLAVOR == 'standalone' }} | |
run: | | |
galaxykit -s http://localhost:8002/api/galaxy/ -u admin -p admin collection list | |
- name: "Ensure galaxykit can connect to API (insights)" | |
if: ${{ env.BACKEND_FLAVOR == 'insights' }} | |
run: | | |
galaxykit -s http://localhost:8002/api/automation-hub/ \ | |
-u admin -p admin \ | |
--auth-url http://localhost:8002/auth/realms/redhat-external/protocol/openid-connect/token \ | |
collection list | |
- name: "Check initial feature flags (community)" | |
if: ${{ env.BACKEND_FLAVOR == 'community' }} | |
run: | | |
curl -s http://localhost:5001/api/_ui/v1/feature-flags/ | jq | |
- name: "Check initial feature flags (standalone)" | |
if: ${{ env.BACKEND_FLAVOR == 'standalone' }} | |
run: | | |
curl -s http://localhost:5001/api/galaxy/_ui/v1/feature-flags/ | jq | |
- name: "Check initial feature flags (insights)" | |
if: ${{ env.BACKEND_FLAVOR == 'insights' }} | |
run: | | |
curl -s http://localhost:5001/api/automation-hub/_ui/v1/feature-flags/ | jq | |
- name: "Check component versions & settings (community)" | |
if: ${{ env.BACKEND_FLAVOR == 'community' }} | |
run: | | |
HUB_TOKEN=`curl -s -u admin:admin -d '' http://localhost:5001/api/v3/auth/token/ | jq -r .token` | |
curl -s -H "Authorization: Token $HUB_TOKEN" http://localhost:5001/api/ | jq | |
curl -s -H "Authorization: Token $HUB_TOKEN" http://localhost:5001/api/_ui/v1/settings/ | jq | |
- name: "Check component versions & settings (standalone)" | |
if: ${{ env.BACKEND_FLAVOR == 'standalone' }} | |
run: | | |
HUB_TOKEN=`curl -s -u admin:admin -d '' http://localhost:5001/api/galaxy/v3/auth/token/ | jq -r .token` | |
curl -s -H "Authorization: Token $HUB_TOKEN" http://localhost:5001/api/galaxy/ | jq | |
curl -s -H "Authorization: Token $HUB_TOKEN" http://localhost:5001/api/galaxy/_ui/v1/settings/ | jq | |
- name: "Check component versions & settings (insights)" | |
if: ${{ env.BACKEND_FLAVOR == 'insights' }} | |
run: | | |
BEARER=`curl -s -H "Content-Type: application/x-www-form-urlencoded" \ | |
-d "client_id=cloud-services&username=admin&password=admin&grant_type=password" \ | |
http://localhost:8002/auth/realms/redhat-external/protocol/openid-connect/token | jq -r .access_token` | |
curl -s -H "Authorization: Bearer $BEARER" http://localhost:8002/api/automation-hub/ | jq | |
curl -s -H "Authorization: Bearer $BEARER" http://localhost:8002/api/automation-hub/_ui/v1/settings/ | jq | |
- name: "Check if e2e contains only dirs in matrix test array" | |
working-directory: 'ansible-hub-ui' | |
run: | | |
diff -Naur <(ls test/cypress/e2e) <(yq '.jobs.cypress.strategy.matrix.test[]' .github/workflows/cypress.yml | sort) | |
- name: "Cache master screenshots" | |
if: matrix.test == 'screenshots' | |
uses: actions/cache@v3 | |
with: | |
path: ansible-hub-ui/test/screenshots.js/ | |
key: screenshots-${{env.SHORT_BRANCH}}-${{ env.UI_COMMIT_MASTER }} | |
restore-keys: | | |
screenshots-${{env.SHORT_BRANCH}}- | |
- name: "List cached screenshots" | |
if: ${{ matrix.test == 'screenshots' && env.COMPARE_SCREENSHOTS == 'true' }} | |
run: | | |
ls ansible-hub-ui/test/screenshots.js/ | |
- name: "Run cypress" | |
working-directory: 'ansible-hub-ui/test' | |
env: | |
CONSOLE_LOG_TO_TERMINAL: true | |
run: | | |
sed -i '/specPattern:/s/\*\*/${{matrix.test}}/' cypress.config.js | |
grep specPattern cypress.config.js | |
npm run cypress:chrome | |
- name: "List new screenshots" | |
if: matrix.test == 'screenshots' | |
continue-on-error: true | |
run: | | |
ls ansible-hub-ui/test/cypress/screenshots/screenshots.js/ | |
- name: "Compare screenshots" | |
if: ${{ matrix.test == 'screenshots' && env.COMPARE_SCREENSHOTS == 'true' }} | |
working-directory: 'ansible-hub-ui/test' | |
run: | | |
changed=false | |
for orig in screenshots.js/*; do | |
echo $orig | |
new=cypress/screenshots/"$orig" | |
diff=cypress/screenshots/diff--"$(basename "$orig")" | |
num=$(compare -metric RMSE "$orig" "$new" "$diff" 2>&1 | awk '{ print $1 }') | |
echo $num | |
num=${num%.*} | |
if [ "$num" -gt 10 ]; then | |
echo "screenshot $orig changed: $num" 1>&2 | |
changed=true | |
fi | |
done | |
if [ "$changed" = true ]; then | |
echo "Process failed because change occured" | |
exit 1 | |
fi | |
- name: "Move Cache master screenshots" | |
if: ${{ matrix.test == 'screenshots' && env.COMPARE_SCREENSHOTS == 'false' }} | |
working-directory: 'ansible-hub-ui/test' | |
run: | | |
rm -rf screenshots.js/ | |
mv cypress/screenshots/screenshots.js/ ./ | |
- uses: actions/upload-artifact@v3 | |
if: failure() | |
with: | |
name: screenshots_and_videos | |
path: | | |
ansible-hub-ui/test/cypress/screenshots | |
ansible-hub-ui/test/cypress/videos | |
- name: "Kill container, show debug info" | |
if: always() | |
working-directory: 'oci_env' | |
run: | | |
oci-env exec bash -c "pip3 list && pip3 install pipdeptree && pipdeptree" | |
oci-env compose logs | |
oci-env compose kill |