GitHub Action Vitest CI pipeline - github-actions

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

Related

Run GitHub workflow from non-gradle project

I have a non-gradle root project which should launch child gh action, but can’t figure out how to. File child.yml should generate apk artifact, since android/ dir is app directory.
Project structure:
root
|
--- .github/workflows/root.yml
--- android/
|
___ .github/actions/apk/child.yml
Closest I get was running a yaml on root level:
root.yml
name: use my action
on:
push:
branches:
- ci_test
jobs:
#Build job
test_build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout#v2
- uses: ./android/.github/actions/apk
child.yml
name: Build of dev branch
on:
push:
branches:
- develop
jobs:
#Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout#v2
- uses: actions/cache#v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
- name: Set up JDK 11
uses: actions/setup-java#v1
with:
java-version: '11'
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build the app
run: ./gradlew assembleDebug
- name: Upload apk
uses: actions/upload-artifact#v2
with:
name: debug apk
path: ./app/build/outputs/apk/debug/app-debug.apk
But I get an error with doubled "/my-root-dir/my-root-dir"
Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/my-root-dir/my-root-dir/android/.github/actions/child.yaml'. Did you forget to run actions/checkout before running your local action?

Running Github actions in another directory

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'

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

How to deploy GitHub Action for my KMM project

Currently, I got some problems when I try to write the YAML file for deploying the GitHub action for KMM project. I don't know how to write the correct script (gradlew command) about testing the code of the shared module. Here's a part of my YAML file:
test_job:
name: Test
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Set up JDK 11
uses: actions/setup-java#v2
with:
java-version: '11'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action#e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Restore Cache
uses: actions/cache#v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Make gradle executable
run: chmod +x ./gradlew
- name: Run Debug Tests
run: ./gradlew testDebugUnitTest --continue
- name: Upload Test Reports
if: ${{ always() }}
uses: actions/upload-artifact#v2
with:
name: test-reports
path: '**/build/reports/tests/'
You can use:
./gradlew check to run tests for all your targets
./gradlew <targetName>Test to run it for a specific target
Note that probably you'd want to specify the shared module as well, for ex: ./gradlew :shared:check
For more information you could check out: https://kotlinlang.org/docs/mpp-run-tests.html#run-tests-for-one-or-more-targets

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