Only re-run the failed job in a GitHub Actions matrix - continuous-integration

How can I re-run only a failed job in a GitHub Actions matrix?
I only want to run the failed jobs and not all of them. My CI matrix takes a lot of time to run, and I don't want to waste energy re-running the whole matrix because one of them failed.
So this button is not my solution:

Re-run a specific job has not been implemented yet, but it is on the roadmap.
However, reading this ISSUE about the subject, there is a workaround from this post, which stores the last run status in cache and then skips jobs based on that status.
How they used it:
- name: Set default run status
run: echo "::set-output name=last_run_status::default" > last_run_status
- name: Restore last run status
id: last_run
uses: actions/cache#v2
with:
path: |
last_run_status
key: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ steps.date.outputs.date }}
restore-keys: |
${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-
- name: Set last run status
id: last_run_status
run: cat last_run_status
- name: Checkout ref
uses: actions/checkout#v2
with:
ref: ${{ github.event.workflow_dispatch.ref }}
- name: Use Node.js ${{ matrix.node-version }}
if: steps.last_run_status.outputs.last_run_status != 'success'
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
Here is the original workflow file.

GitHub finally made it possible to do this. There is now a "Re-run failed jobs" button:

Related

GitHub Actions: run test on staging branch after comment on a pull request

I have a github actions workflow that runs my cypress tests after a comment on a pull request. The problem is that it seems to run the cypress tests against the master branch. I want the tests to run against the staging branch. How can I get the tests to run against the staging branch after a comment on a pull request?
Here is what my yaml file currently looks like:
name: Cypress Staging Tests
on:
issue_comment:
types: [created]
jobs:
identify-staging-deploy:
runs-on: ubuntu-latest
name: deploy to staging comment on pr
if: contains(github.event.comment.body, 'Successful Gordon Deploy')
steps:
- name: Github API Request
id: gh_request
uses: octokit/request-action#v2.0.2
with:
route: GET /repos/:repository/pulls/:issue_id
repository: ${{ github.repository }}
issue_id: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: github secret
- name: Get PR information
id: pr_info
run: |
echo "::set-output name=branch::${{ fromJson(steps.gh_request.outputs.data).head.ref }}"
echo "::set-output name=repo_name::${{ fromJson(steps.gh_request.outputs.data).head.repo.full_name }}"
echo "::set-output name=pr_title::${{ fromJson(steps.gh_request.outputs.data).title }}"
- name: Checkout repo
uses: actions/checkout#v2.3.4
with:
token: dispatch token
repository: ${{ steps.pr_info.outputs.repo_name }}
ref: ${{ steps.pr_info.outputs.branch }}
run-cypress-tests:
needs: identify-staging-deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Node
uses: actions/setup-node#v3
with:
node-version: 12
- name: Install dependencies
run: yarn ci:setup
- name: Cypress Run
id: cypress-results
uses: cypress-io/github-action#v4
with:
browser: chrome
record: true
env:
CYPRESS_fileConfig: staging
- name: Post PR Comment
if: always()
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository_owner }}/repo_name/issues/${{ github.event.issue.number }}/comments \
-f body='#### Cypress Tests: ${{ steps.cypress-results.outcome }}. See results at ${{ steps.cypress-results.outputs.dashboardUrl }}'
env:
GITHUB_TOKEN: dispatch token

How to workaround "The command line is too long" with GraalVM and Windows?

I'm trying to make a JHipster 7 app build with GraalVM on Windows. I've successfully got it to work with macOS and Linux. With Windows, I get an error about the command line being too long.
[INFO] Executing: C:\Users\runneradmin\.graalvm\graalvm-ce-java17-22.0.0.2\bin\native-image.cmd -cp ...;D:\a\auth0-full-stack-java-example\auth0-full-stack-java-example\target\flickr-2-0.0.1-SNAPSHOT.jar --no-fallback --verbose -J-Xmx10g -H:Name=native-executable
The command line is too long.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
I've copied and pasted the command that GitHub Actions runs and it's just over 12,000 characters long. According to this document, Windows only supports 8191 characters.
I tried shortening up the classpath using this suggestion, but it doesn't help. I even tried C:\r instead of C:\repo.
People on Twitter suggested using PowerShell and echoing the commands into a file, and then running that. However, I haven't been able to find any examples of how to extract the native-image.cmd command and its arguments from Maven.
You can find the GitHub action I'm using to configure things here. I've also pasted it below for convenience.
name: Publish
on:
release:
types: [published]
env:
graalvm_version: '22.0.0.2'
java_version: '17'
branch: 'spring-native'
jobs:
build:
name: GraalVM - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout#v2
with:
ref: '${{ env.branch }}'
- name: Set up GraalVM (Java ${{ env.java_version }})
uses: graalvm/setup-graalvm#v1
with:
version: '${{ env.graalvm_version }}'
java-version: '${{ env.java_version }}'
components: 'native-image'
- name: Cache Maven dependencies
uses: actions/cache#v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven
- name: Cache npm dependencies
uses: actions/cache#v2
with:
path: |
~/.npm
~/.cache/Cypress/
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
- name: Set up swap space
if: runner.os == 'Linux'
uses: pierotofy/set-swap-space#v1.0
with:
swap-size-gb: 10
- name: Build native images
run: ./mvnw -B -ntp package -Pnative,prod -DskipTests
- name: Archive binary
uses: actions/upload-artifact#v2
with:
name: flickr2-${{ matrix.os }}-x86_64
path: target/native-executable
- name: Get release version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Rename binary
run: mv target/native-executable target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64
- name: Upload release
uses: alexellis/upload-assets#0.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_paths: '["target/flickr2-${{ runner.os }}*"]'
build-windows:
name: GraalVM - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
os: [windows-latest]
steps:
- uses: actions/checkout#v2
with:
ref: '${{ env.branch }}'
- uses: ilammy/msvc-dev-cmd#v1
- uses: microsoft/setup-msbuild#v1
- name: Set up GraalVM (Java ${{ env.java_version }})
uses: graalvm/setup-graalvm#v1
with:
version: '${{ env.graalvm_version }}'
java-version: '${{ env.java_version }}'
components: 'native-image'
- name: Cache Maven dependencies
uses: actions/cache#v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven
- name: Cache npm dependencies
uses: actions/cache#v2
with:
path: |
~/.npm
~/.cache/Cypress/
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
- name: Configure pagefile
uses: al-cheb/configure-pagefile-action#v1.2
- name: Set up pagefile
run: |
(Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize
- name: mvnw --version
run: mvnw --version
shell: cmd
- name: Maven resolve
run: mvnw -B -ntp dependency:resolve-plugins
shell: cmd
- name: Build native images
run: |
mklink /J C:\r C:\Users\runneradmin\.m2\repository
mvnw -B -ntp package -Pnative,prod -DskipTests -Dmaven.repo.local=C:\r
shell: cmd
- name: Archive binary
uses: actions/upload-artifact#v2
with:
name: flickr-${{ matrix.os }}-x86_64.exe
path: target/native-executable.exe
- name: Get release version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Rename binary
run: move target/native-executable.exe target/flickr2-${{ runner.os }}-${{ env.RELEASE_VERSION }}-x86_64.exe
- name: Upload release
uses: alexellis/upload-assets#0.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_paths: '["target/flickr2-${{ runner.os }}*"]'
Upgrading to native-build-tools v0.9.10 fixes this issue on Windows. More details at https://github.com/graalvm/native-build-tools/issues/214 and https://github.com/graalvm/setup-graalvm/issues/6#issuecomment-1054582083.

How to solve this error `Path does not exist /home/runner/work/cypress-tests/cypress-tests/cypress/screenshots`?

I have a Github workflow and below is the file:
workflow_dispatch:
jobs:
cypress-run:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- run: echo "TEMP PIPELINE FOR Fix-GithubSecrets"
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Checkout
uses: actions/checkout#v1
- name: Run npm ci
uses: actions/setup-node#v1
- run: npm ci
- name: Run Cypress Tests
env:
CYPRESS_QA_AUTH_TOKEN_BUYER: ${{ secrets.QA_AUTH_TOKEN_BUYER }}
CYPRESS_QA_AUTH_TOKEN_INTERNAL: ${{ secrets.QA_AUTH_TOKEN_INTERNAL }}
CYPRESS_QA_AUTH_TOKEN_SELLER: ${{ secrets.QA_AUTH_TOKEN_SELLER }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_APIPASSWORD: ${{ secrets.CYPRESS_APIPASSWORD }}
CYPRESS_APIUSERNAME: ${{ secrets.CYPRESS_APIUSERNAME }}
CYPRESS_TOKEN: ${{ secrets.CYPRESS_TOKEN }}
uses: cypress-io/github-action#v2
with:
record: true
- name: Upload Screenshot Artifacts
uses: actions/upload-artifact#v1
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
And when I run this I am getting error: Path does not exist /home/runner/work/cypress-tests/cypress-tests/cypress/screenshots
How do I create the screenshot folder with the above workflow?
Add a step creating the folder first:
- name: Run Cypress Tests
...
- name: Create folder
run: |
mkdir -p cypress/screenshots
- name: Upload Screenshot Artifacts
...
You can seen other examples in "How to create a folder in github workflow?".

"The cypress npm package is installed, but the Cypress binary is missing." in GitHub Actions

I'm receiving the following error when running a Cypress e2e test runner on GitHub Actions:
The cypress npm package is installed, but the Cypress binary is missing.
We expected the binary to be installed here: /home/runner/.cache/Cypress/8.5.0/Cypress/Cypress
Reasons it may be missing:
- You're caching 'node_modules' but are not caching this path: /home/runner/.cache/Cypress
- You ran 'npm install' at an earlier build step but did not persist: /home/runner/.cache/Cypress
My .github/workflow/tests.yml is set up as follows:
name: celestia/tests
on:
pull_request:
branches:
- main
- master
jobs:
unit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout ๐Ÿ›Ž
uses: actions/checkout#master
# Setup .npmrc file to publish to GitHub Packages
- name: Setup node env ๐Ÿ— and .npmrc file to publish to GitHub Packages
uses: actions/setup-node#v2.1.2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file:
scope: '#observerly'
- name: Cache node_modules ๐Ÿ“ฆ
uses: actions/cache#v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install project dependencies ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
run: npm ci --ignore-scripts
- name: Run jest unit tests ๐Ÿงช
run: npm run test:unit
e2e:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout ๐Ÿ›Ž
uses: actions/checkout#master
# Setup .npmrc file to publish to GitHub Packages
- name: Setup node env ๐Ÿ— and .npmrc file to publish to GitHub Packages
uses: actions/setup-node#v2.1.2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file:
scope: '#observerly'
- name: Install project dependencies ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
run: npm ci --ignore-scripts
- name: Run e2e cypress tests ๐Ÿงช
run: npm run test:e2e:headless
How can I side-step this particular issue?

Github action not caching node_modules across jobs

I have a Github action on pull_request, and am attempting to cache node_modules between jobs. I can only see cache working on a job re-run, but not when opening new PRs, even when there have been no changes to my node_modules.
Is this by design?
Each time it runs in a new PR, I see this output in the job:
Run actions/cache#v2
with:
path: ~/.npm
key: Linux-build-cache-node-modules-83fc6365b85dd061416fccd5993d48c2003c388bb2184fd57f28d1041d9d261e
restore-keys: Linux-build-cache-node-modules-
Linux-build-
Linux-
env:
cache-name: cache-node-modules
Cache not found for input keys: Linux-build-cache-node-modules-83fc6365b85dd061416fccd5993d48c2003c388bb2184fd57f28d1041d9d261e, Linux-build-cache-node-modules-, Linux-build-, Linux-
Yet, re-running the job will enjoy the cache hit:
Run actions/cache#v2
Received 54525952 of 109978126 (49.6%), 51.8 MBs/sec
Received 109978126 of 109978126 (100.0%), 67.8 MBs/sec
Cache Size: ~105 MB (109978126 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/0bdf436d-9d4d-4397-b8ed-5910ff503949/cache.tzst -P -C /home/runner/work/argutopia/argutopia
Cache restored successfully
Cache restored from key: Linux-build-cache-node-modules-83fc6365b85dd061416fccd5993d48c2003c388bb2184fd57f28d1041d9d261e
Here is my action yml for reference:
name: PR CI
on:
pull_request:
branches: [main, develop]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout#v2
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache#v2
id: cache
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
echo '::debug::deps cache miss - installing deps'
npm install
Caching ~/.npm wont allow you to skip running npm install. It will save the global npm cache on this machine so that running npm install doesn't incur as much download time, but you'll then still need to build the local node_modules for your project.
If you want to be able to skip your install, you can cache the project node_modules folder as well and skip install on cache hits there, though this could present some issues down the road.
Use advanced alternative caching technique from this article
- name: Cache dependencies
id: cache
uses: actions/cache#v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts

Resources