Running Github actions in another directory - github-actions

I would like to execute a github action in a sub-directory of my project because my Github repo contains 2 applications (front/back) and I need to test the front. (see below)
my-project
├─ api/
│ └─ ...
└─ front-app/
└─ (node-js application I want to run the tests for)
I want to execute only the tests for the front-app running on svelte (node-js)
The tests fails because they run in the project directory instead of the front-app/ one.
However I already implemented :
# Just after `on: push / pull_request`
defaults:
run:
working-directory: ./front-app/
# And before `jobs`
And I still get the error :
Run actions/setup-node#v3
Found in cache # /opt/hostedtoolcache/node/16.16.0/x64
/opt/hostedtoolcache/node/16.16.0/x64/bin/npm config get cache
/home/runner/.npm
Error: Dependencies lock file is not found in /home/runner/work/my-project/my-project. Supported file patterns: package-lock.json,npm-shrinkwrap.json,yarn.lock
The file is define as :
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Tests for front-app
on:
push:
branches: [ "main" ]
paths: ["front-app/**"]
pull_request:
branches: [ "main" ]
paths: ["front-app/**"]
defaults:
run:
working-directory: ./front-app/
jobs:
test-front-app:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3 # <-- I think the error occurs here
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci # <-- This is not executed - The error occurs before
- run: npm run build --if-present
- run: npm test

So, I found the solution in the documentation here by adding cache-dependency-path: with the path of the package-lock.json (see below)
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'front-app/package-lock.json'

Related

GitHub Action Vitest CI pipeline

I would like to create a CI pipeline with GitHub Action but I have problems. The front end of the project is developed in Vue 3 and uses vitest to run the tests. It's in a folder called "WEB" in the root directory. So I would like to run my tests at each commit in the master branch but it returns this error:
Error: .github#L1
each step must define a `uses` or `run` key
I used the preexisting "Node.js" template and just added the "working-directory" property to specify the "WEB" folder.
Here is my ".yml" file
name: Runs frontend tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
working-directory: ./WEB
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Execute Unit tests
- run: npm ci
- run: npm run test
When you add a - it add an element at the steps array:
You should do it like this:
- name: Execute Unit tests
run: |
npm ci
npm run test

How to use environment vars in GitHub actions?

env:
APP_PATH: ${{ github.workspace }}/MyApp/Build/Applications/MyApp.app
jobs:
build:
runs-on: macos-latest
steps:
- name: Upload app
uses: svenstaro/upload-release-action#v2
with:
file: ${APP_PATH}
This fails with:
Error: ENOENT: no such file or directory, stat '${APP_PATH}'
The docs say to use, e.g. $DAY_OF_WEEK, but it doesn't work. I've tried $APP_PATH, ${APP_PATH}, and ${{APP_PATH}}.

GitHub Actions - Cache CMake build

On every commit, I'm building my project on different Operating Systems. Therefore I'm using CMake as a build system for my C++ code.
In order to make the builds faster I tried to cache older builds, so not changed files don't have to be rebuilt.
I've written the following GH Action Script:
name: Build for MacOS, Ubuntu and Windows
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-11, windows-2022 ]
steps:
- uses: actions/checkout#v2
- name: Cache build
uses: actions/cache#v3
with:
path: ${{github.workspace}}/build
key: ${{ matrix.os }}-build
restore-keys: ${{ matrix.os }}-build
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DFORCE_COLORED_OUTPUT=1
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Width ...
- name: Cache build
uses: actions/cache#v3
with:
path: ${{github.workspace}}/build
key: ${{ matrix.os }}-build
restore-keys: ${{ matrix.os }}-build
... I tried to cache the directory all the build files are written to, but it looks like the project is completely rebuilt every time.
Is there anything I'm doing wrong?
I uploaded all logs to https://pastebin.com/JLErAPyD

Github actions release workflow not running for releases created via github actions

We're using changesets action to generate releases and publish to NPM. Here's an example:
Action Log
Release created by that run
The action that I want to run for each release is meant to upload some artifacts.
name: Bundle
on:
release:
types:
- created
- published
- prereleased
- released
jobs:
bundle:
# Prevents changesets action from creating a PR on forks
if: github.repository == 'patternfly/patternfly-elements'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
cache: npm
- name: Install packages
run: npm i --prefer-offline
- name: Dump GitHub Context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Bundle
id: bundle
if: ${{ steps.changesets.outputs.published }}
uses: actions/github-script#v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const workspace = '${{ github.workspace }}';
const bundle = require('./scripts/bundle-release.cjs');
await bundle({ context, github, glob, workspace });
I expected this workflow to run immediately after the changesets publish run, but it did not. In fact it hasn't run once since being added to the repo.
What could be causing this issue?

How to trigger gh-pages branch changes via another action

I got this action which publishes to gh-pages successfully :
name: Deployment
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout#v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Packages
run: npm install
- name: Build page
run: npm run build
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages#v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./build
I added second action
name: S3Publish
on:
push:
branches:
- gh-pages
... but it never triggers
We can also put .github directory including your second workflow to the gh-pages branch.
- name: Deploy
uses: peaceiris/actions-gh-pages#v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} # Recommended
personal_token: ${{ secrets.PERSONAL_TOKEN }} # An alternative
# github_token: ${{ secrets.GITHUB_TOKEN }} # Dot not use this token for this case.
exclude_assets: ''
Set exclude_assets to empty for including the .github directory to deployment assets.
For more details, see the latest README: How to trigger gh-pages branch changes via another action - Stack Overflow