Skip to content

Commit 73fd151

Browse files
committed
rancher/cypress add release workflow; add publish and move build script
Signed-off-by: Francesco Torchia <[email protected]>
1 parent dfd19a8 commit 73fd151

File tree

5 files changed

+136
-4
lines changed

5 files changed

+136
-4
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish Cypress Suite Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'cypress-pkg-v*'
7+
workflow_call:
8+
inputs:
9+
tag:
10+
required: false
11+
type: string
12+
outputs:
13+
build-release-cypress-suite-status:
14+
value: ${{ jobs.build.outputs.build-status }}
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
working-directory: ./cypress
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
if: github.repository == 'rancher/dashboard' && (github.event_name == 'workflow_call' || (github.event_name == 'push' && github.event.ref == 'refs/tags/${{ github.ref_name }}'))
28+
outputs:
29+
build-status: ${{ job.status }}
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v6
33+
with:
34+
fetch-depth: 0
35+
persist-credentials: false
36+
37+
- name: Setup Node.js
38+
uses: actions/setup-node@v6
39+
with:
40+
node-version-file: '.nvmrc'
41+
cache: 'yarn'
42+
43+
- uses: actions/setup-node@v6
44+
with:
45+
node-version-file: '.nvmrc'
46+
registry-url: 'https://registry.npmjs.org'
47+
scope: '@rancher'
48+
49+
- name: Install packages
50+
run: yarn install --frozen-lockfile
51+
52+
- name: Build Cypress Package
53+
run: yarn build-pkg
54+
55+
- name: Publish Cypress Package to npm
56+
run: yarn publish-pkg
57+
env:
58+
TAG: ${{ inputs.tag || github.ref_name }}
59+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

cypress/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ cy.fixture('@rancher/cypress/blueprints/fixture.json').then((data) => {
160160
### Publishing
161161
- To manual publish, run:
162162
```bash
163-
npm run build
163+
yarn build-pkg
164164
cd dist
165165
npm publish
166166
```

cypress/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"directory": "cypress"
5454
},
5555
"scripts": {
56-
"build": "./build.sh"
56+
"build-pkg": "./scripts/build.sh",
57+
"publish-pkg": "./scripts/publish.sh --npm"
5758
}
5859
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
22

33
# Build script for @rancher/cypress package
4+
# Run this script from the cypress/ directory
45

56
echo "Building @rancher/cypress package..."
67

7-
# Ensure we're in the cypress directory
8-
cd "$(dirname "$0")"
8+
9+
# Move to the cypress root directory (one level up from scripts/)
10+
cd "$(dirname "$0")/.."
911

1012
# Clean previous builds
1113
rm -rf dist/

cypress/scripts/publish.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
6+
BASE_DIR="$(cd $SCRIPT_DIR && cd ../.. && pwd)"
7+
CYPRESS_DIR=$BASE_DIR/cypress/
8+
FORCE_PUBLISH_TO_NPM="false"
9+
DEFAULT_NPM_REGISTRY="https://registry.npmjs.org"
10+
11+
# if TAG doesn't exist, we can exit as it's needed for any type of publish.
12+
if [ -z "$TAG" ]; then
13+
echo "Missing TAG environment variable"
14+
exit 1
15+
fi
16+
17+
# if TAG does not start with cypress-pkg-v we can exit as it's needed for any type of publish.
18+
if [[ "$TAG" != cypress-pkg-v* ]]; then
19+
echo "TAG does not start with cypress-pkg-v, skipping publish"
20+
exit 0
21+
fi
22+
23+
if [ ! -d "${CYPRESS_DIR}/node_modules" ]; then
24+
echo "Missing node_modules in cypress/. Please run 'yarn install' in the root directory first."
25+
exit 1
26+
fi
27+
28+
if [ "$1" == "--npm" ]; then
29+
FORCE_PUBLISH_TO_NPM="true"
30+
fi
31+
32+
if [ "$FORCE_PUBLISH_TO_NPM" == "true" ]; then
33+
export NPM_REGISTRY=$DEFAULT_NPM_REGISTRY
34+
fi
35+
36+
echo "Publishing @rancher/cypress package..."
37+
echo ""
38+
echo "TAG: $TAG"
39+
echo "BASE_DIR: $BASE_DIR"
40+
echo "CYPRESS_DIR: $CYPRESS_DIR"
41+
echo "NPM_REGISTRY: $NPM_REGISTRY"
42+
echo "FORCE_PUBLISH_TO_NPM: $FORCE_PUBLISH_TO_NPM"
43+
echo ""
44+
45+
PUBLISH_ARGS="--no-git-tag-version --access public --registry $NPM_REGISTRY"
46+
47+
# Remove cypress-pkg-v prefix from version tag if exists
48+
PKG_VERSION="${TAG#cypress-pkg-v}"
49+
50+
# Update the version in dist/package.json to match the pkg version
51+
echo "Setting package version to ${PKG_VERSION}"
52+
echo ""
53+
jq --arg ver "$PKG_VERSION" '.version = $ver' ./dist/package.json > ./dist/package.tmp.json && mv ./dist/package.tmp.json ./dist/package.json
54+
55+
# if the PKG_VERSION has a - it means it will be a pre-release
56+
if [[ $PKG_VERSION == *"-"* ]]; then
57+
PUBLISH_ARGS="$PUBLISH_ARGS --tag pre-release"
58+
fi
59+
60+
echo "Publish ${PKG_VERSION} with arguments: ${PUBLISH_ARGS}"
61+
echo ""
62+
63+
cd ./dist
64+
npm publish ${PUBLISH_ARGS}
65+
RET=$?
66+
67+
if [ $RET -ne 0 ]; then
68+
echo "Error publishing package @rancher/cypress version ${PKG_VERSION}"
69+
exit $RET
70+
fi

0 commit comments

Comments
 (0)