Multiple npm tests in one Github action - github-actions

I have 3 repos, A,B and C. A is the parent. In the A repo i have a github action, see below.
Package B and C are in package A.
Is it possible and how can i achive to run npm test for repo B en C BEFORE i run the test for repo A?
on:
push:
tags:
- '*'
name: πŸš€ Deploy website on create tag
jobs:
web-deploy:
name: πŸŽ‰ Deploy
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout#v2
- name: Use Node.js 14
uses: actions/setup-node#v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
scope: '#xxxxxx'
- name: πŸ”¨ NPM install en build prod
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
- run: npm ci
- run: npm run build
- run: npm run test
- name: Copy public dir to production
uses: appleboy/scp-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{secrets.SSH_PRIVATE_KEY}}
port: ${{secrets.SSH_PORT}}
command_timeout: 30s
source: "./public"
target: "/var/www/html/"

You could define a job for each testing step A,B and C described here. In the code below B and C are each in their own working-directory (/B and /C) within the repository A.
B and C run in parallel. After BOTH have completed successfully job A is run. (Based on your code, not tested)
jobs:
B:
name: Do job B
runs-on: ubuntu-latest
defaults:
run:
working-directory: 'B'
steps:
- name: 🚚 Get latest code
uses: actions/checkout#v2
- name: Use Node.js 14
uses: actions/setup-node#v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
scope: '#xxxxxx'
- name: πŸ”¨ NPM install en build prod
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
- run: npm ci
- run: npm run build
- run: npm run test
C:
name: Do job C
runs-on: ubuntu-latest
defaults:
run:
working-directory: 'C'
steps:
- name: 🚚 Get latest code
uses: actions/checkout#v2
- name: Use Node.js 14
uses: actions/setup-node#v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
scope: '#xxxxxx'
- name: πŸ”¨ NPM install en build prod
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
- run: npm ci
- run: npm run build
- run: npm run test
A:
name: Do job A
needs: [B, C]
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout#v2
- name: Use Node.js 14
uses: actions/setup-node#v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
scope: '#xxxxxx'
- name: πŸ”¨ NPM install en build prod
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
- run: npm ci
- run: npm run build
- run: npm run test
- name: Copy public dir to production
uses: appleboy/scp-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{secrets.SSH_PRIVATE_KEY}}
port: ${{secrets.SSH_PORT}}
command_timeout: 30s
source: "./public"
target: "/var/www/html/"

I found the solution.
on:
push
name: πŸš€ Deploy website on create tag
jobs:
web-deploy:
name: πŸŽ‰ B
runs-on: ubuntu-latest
steps:
- name: Check out my other private repo
uses: actions/checkout#master
with:
repository: 'bbb/bbb'
token: ${{ secrets.PAT }}
- name: πŸ”¨ NPM install en build prod
- run: npm ci
- run: npm run build
- run: npm run test
web-deploy:
name: πŸŽ‰ C
runs-on: ubuntu-latest
steps:
- name: Check out my other private repo
uses: actions/checkout#master
with:
repository: 'ccc/ccc'
token: ${{ secrets.PAT }}
- name: πŸ”¨ NPM install en build prod
- run: npm ci
- run: npm run build
- run: npm run test
And the rest...

Related

GitHub Actions fails with: "An error occurred trying to start process '/usr/bin/bash' with working directory"

The Error from GitHub:
An error occurred trying to start process '/usr/bin/bash' with working directory '/home/runner/work/myproject-api/myproject-api/app'. No such file or directory
My Workflow File:
name: Docker Build and Push to Docker Hub and ghcr.io
on:
push:
branches:
- 'feature/auto-deploy-dev'
defaults:
run:
working-directory: app
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Set up QEMU
uses: docker/setup-qemu-action#v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action#v1
- name: Login to DockerHub
uses: docker/login-action#v1
with:
username: ${{ secrets.SECRET }}
password: ${{ secrets.TOKEN }}
- name: Build and push
uses: docker/build-push-action#v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
file: Dockerfile
tags: |
repo/project:latest
- name: Checkout
uses: actions/checkout#v2
- name: KubeCtl Command
uses: tale/kubectl-action#v1
with:
base64-kube-config: ${{ secrets.KUBECONFIG }}
- run: kubectl get pods -n myNamespace

fatal: could not read Username for 'https://github.com': terminal prompts disabled

I'm trying to integrate Lighthouse CI into my CI/CD to generate reports on my applications performance. I'm using GitHub Actions, and other jobs like building the app and generating a SonarCloud scan are working.
However Lighthouse CI is not working. The error is: Error: fatal: could not read Username for 'https://github.com': terminal prompts disabled
Code:
# 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: Node.js CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action#master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v3
with:
token: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node#v3
with:
node-version: 16.x
- name: Run the Lighthouse CI
run: |
npm install -g #lhci/cli#0.6.x
lhci autorun
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
node-version: [ 16.x ]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: Log in to the Container registry
uses: docker/login-action#f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action#98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha
- name: Build and push Docker image
uses: docker/build-push-action#ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Screenshot of GitHub Actions:
hi,i find a issue for the problem。
https://github.com/actions/checkout/issues/664
β€œFor a simple checkout indeed no PAT is required.”
so you can try remove token
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v3
with:
# token: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} // remove
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node#v3
with:
node-version: 16.x
- name: Run the Lighthouse CI
run: |
npm install -g #lhci/cli#0.6.x
lhci autorun

github actions failure to build-and-push-docker-images

Trying to build and push docker image for java-gradle project, Below is the action script:
name: Java CI with Gradle
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Login to DockerHub
uses: docker/login-action#v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action#v2
with:
context: .
push: true
tags: user/app:latest
The error lies with login to dockerhub in the script. Below is the error obtained, not sure if it is correct?
*
Run docker/login-action#v1
Error: Username and password required
*
Please help.

Github actions failing on installation of dependencies

Github actions throwing error:
Run composer install -q --no-ansi --no-interaction --no-scripts
--no-progress --prefer-dist composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist shell: /usr/bin/bash -e {0} Error: The operation was canceled.
Please see configuration and image below:
Laravel.yml file
name: Laravel
on:
push:
branches:
- master
- develop
- features/**
pull_request:
branches:
- master
- develop
jobs:
laravel-tests:
runs-on: ubuntu-latest
# Service container Postgresql postgresql
services:
# Label used to access the service container
postgres:
# Docker Hub image (also with version)
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test_laravel
## map the "external" 55432 port with the "internal" 5432
ports:
- 55432:5432
# Set health checks to wait until postgresql database has started (it takes some seconds to start)
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.0','7.4' ]
dependency-stability: [ prefer-stable ]
name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}
steps:
- uses: actions/checkout#v2
- name: Setup Node.js
uses: actions/setup-node#v1
with:
node-version: '15.x'
- name: Cache node_modules directory
uses: actions/cache#v2
id: node_modules-cache
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
- name: Install NPM packages
if: steps.node_modules-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build frontend
run: npm run development
- name: Install PHP versions
uses: shivammathur/setup-php#v2
with:
php-version: ${{ matrix.php-versions }}
- name: Get Composer Cache Directory 2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache#v2
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Cache PHP dependencies
uses: actions/cache#v2
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Run Migrations
# Set environment
env:
DB_CONNECTION: pgsql
DB_DATABASE: db_test_laravel
DB_PORT: 55432
DB_USERNAME: postgres
DB_PASSWORD: postgres
run: php artisan migrate
- name: Show dir
run: pwd
- name: PHP Version
run: php --version
# Code quality
- name: Execute tests (Unit and Feature tests) via PHPUnit
# Set environment
env:
DB_CONNECTION: pgsql
DB_DATABASE: db_test_laravel
DB_PORT: 55432
DB_USERNAME: postgres
DB_PASSWORD: postgres
run: vendor/bin/phpunit --testdox
Action summary image
Composer.json
"require": {
"php": "^7.3|^8.0",
Fixed this by doing the following:
Changed the version to php-versions: [ '8.0' ]
Github actions run successfully.

How to get the description or name from a release in github actions

I have read through the documentation for Github actions and the release action, yet I can find nothing on how to get the name from the action. Do I need to run a fetch call or something else?
name: Publish to Bintray
on:
release:
types: [published]
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew curseforge uploadSubProjects publishToModrinth --parallel --stacktrace
env:
BINTRAY_USER: oroarmor
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
CURSE_API_KEY: ${{ secrets.CURSE_API_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
You can use github.event.release.name and github.event.release.body:
name: After Release
on:
release:
types: [published]
jobs:
after-release:
runs-on: ubuntu-latest
steps:
- run: echo "Name: ${{ github.event.release.name }} Description: ${{ github.event.release.body }}"