@cypress/github-action 6.3.0 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +49 -9
  2. package/dist/index.js +76 -0
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -117,14 +117,14 @@ See the example project [component-tests](examples/component-tests/) and the [ex
117
117
 
118
118
  **Best practice:**
119
119
 
120
- Our examples specify using branch [v5](https://github.com/cypress-io/github-action/tree/v5) which is the action's recommended major version:
120
+ Our examples specify using branch [v6](https://github.com/cypress-io/github-action/tree/v6) which is the action's recommended major version:
121
121
 
122
122
  ```yml
123
123
  - name: Cypress run
124
124
  uses: cypress-io/github-action@v6
125
125
  ```
126
126
 
127
- When using `cypress-io/github-action@v6` from your workflow file, you will automatically use the latest [tag](https://github.com/cypress-io/github-action/tags) from branch [v5](https://github.com/cypress-io/github-action/tree/v5).
127
+ When using `cypress-io/github-action@v6` from your workflow file, you will automatically use the latest [tag](https://github.com/cypress-io/github-action/tags) from branch [v6](https://github.com/cypress-io/github-action/tree/v6).
128
128
 
129
129
  Alternatively, to mitigate unforeseen breaks, bind to a specific [tag](https://github.com/cypress-io/github-action/tags), for example:
130
130
 
@@ -239,6 +239,8 @@ Include `options: --user 1001` to avoid permissions issues.
239
239
 
240
240
  Refer to [cypress-io/cypress-docker-images](https://github.com/cypress-io/cypress-docker-images) for further information about using Cypress Docker images. Cypress offers the [Cypress Docker Factory](https://github.com/cypress-io/cypress-docker-images/tree/master/factory) to generate additional Docker images with selected components and versions.
241
241
 
242
+ [![Docker example](https://github.com/cypress-io/github-action/workflows/example-docker/badge.svg?branch=master)](.github/workflows/example-docker.yml)
243
+
242
244
  ### Env
243
245
 
244
246
  Specify the env argument with `env` parameter
@@ -408,7 +410,7 @@ jobs:
408
410
  # let's make sure our "app" works on several versions of Node
409
411
  strategy:
410
412
  matrix:
411
- node: [16, 18, 20]
413
+ node: [18, 20]
412
414
  name: E2E on Node v${{ matrix.node }}
413
415
  steps:
414
416
  - name: Setup Node
@@ -450,8 +452,6 @@ jobs:
450
452
  runs-on: ubuntu-22.04
451
453
  name: E2E
452
454
  steps:
453
- - name: Setup Node
454
- uses: actions/setup-node@v3
455
455
 
456
456
  - name: Checkout
457
457
  uses: actions/checkout@v3
@@ -1133,7 +1133,7 @@ jobs:
1133
1133
  # let's make sure our "app" works on several versions of Node
1134
1134
  strategy:
1135
1135
  matrix:
1136
- node: [16, 18, 20]
1136
+ node: [18, 20]
1137
1137
  name: E2E on Node v${{ matrix.node }}
1138
1138
  steps:
1139
1139
  - name: Setup Node
@@ -1167,7 +1167,7 @@ jobs:
1167
1167
  runs-on: ubuntu-22.04
1168
1168
  strategy:
1169
1169
  matrix:
1170
- node: [16, 18, 20]
1170
+ node: [18, 20]
1171
1171
  name: E2E on Node v${{ matrix.node }}
1172
1172
  steps:
1173
1173
  - uses: actions/setup-node@v3
@@ -1462,13 +1462,53 @@ jobs:
1462
1462
  publish-summary: false
1463
1463
  ```
1464
1464
 
1465
+ ### Automatic PR number & URL detection
1466
+
1467
+ When recording runs to Cypress Cloud, the PR number and URL can be automatically detected if you pass `GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`
1468
+ via the workflow `env`. When set, this value enables the Action to perform additional logic that grabs the related PR number and URL (if they
1469
+ exist) and sets them in the environment variables `CYPRESS_PULL_REQUEST_ID` and `CYPRESS_PULL_REQUEST_URL`, respectively.
1470
+ * See Cypress' documentation on [CI Build Information](https://on.cypress.io/guides/continuous-integration/introduction#CI-Build-Information)
1471
+
1472
+ Example workflow using the variables:
1473
+ ```yml
1474
+ name: Example echo PR number and URL
1475
+ on: push
1476
+ jobs:
1477
+ cypress-run:
1478
+ runs-on: ubuntu-22.04
1479
+ steps:
1480
+ - name: Checkout
1481
+ uses: actions/checkout@v3
1482
+ - name: Cypress run
1483
+ uses: cypress-io/github-action@v6
1484
+ with:
1485
+ record: true
1486
+ - run: echo "PR number is $CYPRESS_PULL_REQUEST_ID"
1487
+ - run: echo "PR URL is $CYPRESS_PULL_REQUEST_URL"
1488
+ env:
1489
+ CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
1490
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1491
+ ```
1492
+
1493
+ #### Triggering event: `pull_request`/`pull_request_target`
1494
+
1495
+ For either of these events, we set `CYPRESS_PULL_REQUEST_ID` and `CYPRESS_PULL_REQUEST_URL` to that of the PR number and URL, respectively, of the
1496
+ PR that triggered the workflow.
1497
+
1498
+ #### Triggering event: `push`
1499
+
1500
+ When a commit on a branch without a PR is made, the Cypress GitHub Action checks to see if the commit that triggered the workflow has a
1501
+ related PR. If the commit exists in any other PRs, it's considered a related PR. When there are related PRs, we grab the first related PR
1502
+ and use that PR's number and URL for `CYPRESS_PULL_REQUEST_ID` and `CYPRESS_PULL_REQUEST_URL`, respectively.
1503
+
1504
+ If no related PR is detected, `CYPRESS_PULL_REQUEST_ID` and `CYPRESS_PULL_REQUEST_URL` will be undefined.
1505
+
1465
1506
  ## Node.js
1466
1507
 
1467
1508
  ### Support
1468
1509
 
1469
1510
  Node.js is required to run this action. The recommended version `v6` supports:
1470
1511
 
1471
- - **Node.js** 16.x
1472
1512
  - **Node.js** 18.x
1473
1513
  - **Node.js** 20.x and above
1474
1514
 
@@ -1480,7 +1520,7 @@ and is generally aligned with [Node.js's release schedule](https://github.com/no
1480
1520
 
1481
1521
  [![Node versions example](https://github.com/cypress-io/github-action/workflows/example-node-versions/badge.svg?branch=master)](.github/workflows/example-node-versions.yml)
1482
1522
 
1483
- Cypress itself runs with a fixed Node.js version specified by the [runs.using](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions) parameter of [action.yml](action.yml). `github-action@v5` uses `node16` and `github-action@v6` uses `node20`.
1523
+ Cypress itself runs with a fixed Node.js version specified by the [runs.using](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions) parameter of [action.yml](action.yml). `github-action@v6` uses `node20`.
1484
1524
 
1485
1525
  ## Changelog
1486
1526
 
package/dist/index.js CHANGED
@@ -74832,6 +74832,80 @@ const waitOnMaybe = () => {
74832
74832
 
74833
74833
  const I = (x) => x
74834
74834
 
74835
+ const detectPrNumber = async () => {
74836
+ const {
74837
+ GITHUB_SHA,
74838
+ GITHUB_TOKEN,
74839
+ GITHUB_RUN_ID,
74840
+ GITHUB_REPOSITORY,
74841
+ GITHUB_HEAD_REF,
74842
+ GITHUB_REF,
74843
+ GITHUB_SERVER_URL,
74844
+ CYPRESS_PULL_REQUEST_ID,
74845
+ CYPRESS_PULL_REQUEST_URL
74846
+ } = process.env
74847
+
74848
+ if (CYPRESS_PULL_REQUEST_ID && CYPRESS_PULL_REQUEST_URL) {
74849
+ // Both pull request envs are already defined - no need to do anything else
74850
+ return
74851
+ }
74852
+
74853
+ const [owner, repo] = GITHUB_REPOSITORY.split('/')
74854
+ let prNumber
74855
+
74856
+ if (GITHUB_TOKEN) {
74857
+ debug(
74858
+ `Detecting PR number by asking GitHub about run ${GITHUB_RUN_ID}`
74859
+ )
74860
+
74861
+ const client = new Octokit({
74862
+ auth: GITHUB_TOKEN
74863
+ })
74864
+
74865
+ if (GITHUB_HEAD_REF) {
74866
+ // GITHUB_HEAD_REF is only defined when the event that triggered it was 'pull_request' or 'pull_request_target' (meaning a PR number should be readily-available)
74867
+ // should have format refs/pull/<pr_number>/merge when triggered by pull_request workflow
74868
+ prNumber = parseInt(GITHUB_REF.split('/')[2])
74869
+ } else {
74870
+ try {
74871
+ const resp = await client.request(
74872
+ 'GET /repos/:owner/:repo/commits/:commit_sha/pulls',
74873
+ {
74874
+ owner,
74875
+ repo,
74876
+ commit_sha: GITHUB_SHA
74877
+ }
74878
+ )
74879
+
74880
+ if (
74881
+ resp &&
74882
+ resp.data &&
74883
+ resp.data[0] &&
74884
+ resp.data[0].number
74885
+ ) {
74886
+ prNumber = resp.data[0].number
74887
+ }
74888
+ } catch (e) {
74889
+ console.error(
74890
+ `Unable to fetch related PR data for commit: '${GITHUB_SHA}': `,
74891
+ e
74892
+ )
74893
+ }
74894
+ }
74895
+
74896
+ if (prNumber) {
74897
+ if (!CYPRESS_PULL_REQUEST_ID) {
74898
+ core.exportVariable('CYPRESS_PULL_REQUEST_ID', prNumber)
74899
+ }
74900
+
74901
+ const url = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/${prNumber}`
74902
+ if (!CYPRESS_PULL_REQUEST_URL) {
74903
+ core.exportVariable('CYPRESS_PULL_REQUEST_URL', url)
74904
+ }
74905
+ }
74906
+ }
74907
+ }
74908
+
74835
74909
  /**
74836
74910
  * Asks Cypress API if there were already builds for this commit.
74837
74911
  * In that case increments the count to get unique parallel id.
@@ -75065,6 +75139,8 @@ const runTests = async () => {
75065
75139
  core.exportVariable('CYPRESS_CACHE_FOLDER', CYPRESS_CACHE_FOLDER)
75066
75140
  core.exportVariable('TERM', 'xterm')
75067
75141
 
75142
+ await detectPrNumber()
75143
+
75068
75144
  if (customCommand) {
75069
75145
  console.log('Using custom test command: %s', customCommand)
75070
75146
  return execCommand(customCommand, true, 'run tests')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/github-action",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "GitHub Action for running Cypress end-to-end and component tests",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -46,11 +46,11 @@
46
46
  "supports-color": "9.3.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/node": "20.5.7",
49
+ "@types/node": "20.5.9",
50
50
  "@vercel/ncc": "0.36.1",
51
51
  "husky": "8.0.3",
52
52
  "markdown-link-check": "3.11.1",
53
- "prettier": "3.0.2"
53
+ "prettier": "3.0.3"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"