Github actions failing on installation of dependencies - github-actions

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.

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

Positional parameter not supported in GitHub Actions

I am starting to get along with GitHub actions, but cannot figure out a Problem here:
this is my GitHub Action yml:
name: Redwood CD for database deployment
on:
push:
branches: ['main']
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
TEST_DATABASE_URL: postgres://postgres:postgres#localhost:5432/postgres
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
# .... here I fetch and build my code which works...
# then I want to tar it and deploy it to caprover --> which does not work:
- name: Compress action step
uses: a7ul/tar-action#v1.1.0
id: compress
with:
command: c
cwd: ./
files: |
/home/runner/work/redwood-tutorial/redwood-tutorial/api/dist/
/home/runner/work/redwood-tutorial/redwood-tutorial/web/dist/
captain-definition
outPath: deploy.tar
- uses: caprover/deploy-from-github#main
with:
server: '${{ secrets.CAPROVER_SERVER }}'
app: '${{ secrets.APP_NAME }}'
token: '${{ secrets.APP_TOKEN }}'
branch: '${{ secrets.DEPLOY_BRANCH }}' # optional
image: '${{ secrets.DEPLOY_IMAGE }}' # optional
and this line:
outPath: deploy.tar seems to give me the following error:
Positional parameter not supported: ./deploy.tar
does anyone know what the problem could be here? Google does not really help me here
Cheers and thanks!

Github workflow: Where does "npm ci" store the "node_modules"-folder

I'm wondering where npm ci saves the node_modules.
Furthermore I want to zip the node_modules. Is this even possible with git workflows or should I try a different approach? I need this workflow to deploy the codebase on git to a lamda function in AWS.
This is my code for example:
jobs:
node:
runs-on: ubuntu-latest
steps:
- name: ๐Ÿ›’ Checkout
uses: actions/checkout#v3
- name: ๐Ÿค– Setup Node
uses: actions/setup-node#v3
with:
node-version: 16.13.2
registry-url: 'https://npm.pkg.github.com'
cache: 'npm'
cache-dependency-path: '**/package.json'
- name: Cache
id: cache-dep
uses: actions/cache#v3
with:
path: |
./node_modules
key: ${{ runner.os }}-pricing-scraper-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-pricing-scraper-
- name: Config NPM
shell: bash
run: |
npm install -g npm#8.1.2
- name: โš™๏ธ Install node_modules
if: steps.cache-dep.outputs.cache-hit != 'true'
shell: bash
run: |
npm ci
build:
runs-on: ubuntu-latest
needs: [node]
steps:
- name: ๐Ÿ›’ Checkout
uses: actions/checkout#v3
- name: ๐Ÿ— Zip files and folder
if: steps.cache-dep.outputs.cache-hit != 'true'
shell: bash
run: |
echo Start running the zip script
# delete prior deployment zips
DIR="./output"
if [ ! -d "$DIR" ]; then
echo "Error: ${DIR} not found. Can not continue."
exit 1
fi
if [ ! -d "./node_modules" ]; then
echo "Error: node_modules not found. Can not continue."
exit 1
fi
rm "$DIR"/*
echo Deleted prior deployment zips
# Zip the core directories which are the same for every scraper.
zip -r "$DIR"/core.zip config node_modules shipping util
...
It's not saved in the repo
- name: Bash Test node_modules
if: steps.cache-dep.outputs.cache-hit != 'true'
shell: bash
run: |
echo "cached"
echo $(ls)
Output:
Run echo "cached"
cached
README.md build config output package-lock.json package.json scraper shipping testHandler.js util
The place where the node_modules are stored is ยด~/.npmยด
The problem was that I did 2 jobs (node, build) on 2 different VMs. So the installed node_modules were on the other VM (node-job) than where I needed them (build-job).

Multiple npm tests in one Github action

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...

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.