Github actions workflow error: You have an error in your yaml syntax - github

I am trying to deploy to google cloud engine using github actions and my yaml config is as follows,
name: "Deploy to GAE"
on:
push:
branches: [production]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install Dependencies
run: composer install -n --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: GCP Authenticate
uses: GoogleCloudPlatform/github-actions/setup-gcloud#master
with:
version: "273.0.0"
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Set GCP_PROJECT
env:
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
run: gcloud --quiet config set project ${GCP_PROJECT}
- name: Deploy to GAE
run: gcloud app deploy app.yaml
and github actions is throwing me the below error
Invalid workflow file: .github/workflows/main.yml#L10
You have an error in your yaml syntax on line 10
fyi, line #10 is - uses: actions/checkout#v2

The steps indentation level is incorrect, it should be inside deploy
name: "Deploy to GAE"
on:
push:
branches: [production]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install Dependencies
run: composer install -n --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: GCP Authenticate
uses: GoogleCloudPlatform/github-actions/setup-gcloud#master
with:
version: "273.0.0"
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Set GCP_PROJECT
env:
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
run: gcloud --quiet config set project ${GCP_PROJECT}
- name: Deploy to GAE
run: gcloud app deploy app.yaml

Related

Artifacts not getting uploaded during Github Actions Build for a MEVN app

As the title suggests, I am building a MEVN (Vue) Stack application and am facing this issue:
Earlier to this, I had been only building the frontedn part of my app & it was successfully getting deployed. Only when did I integrate my backend & changed the folder structure a bit, did I start getting these errors.
Below is my Deploy.yml :
name: Deploy
on:
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout#v2
- name: Setup Node
uses: actions/setup-node#v1
with:
node-version: 16
- name: Install dependencies
uses: bahmutov/npm-install#v1
- name: Build project
run: npm run build --prefix client
- name: Upload production-ready build files
uses: actions/upload-artifact#v2
with:
name: production-files
path: ./dist
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact
uses: actions/download-artifact#v2
with:
name: production-files
path: ./dist
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages#v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
Please help.

Caching artifacts in GitHub actions using runner controller

I want to set up self-hosted runners on a k8s cluster using actions-runner-controller.
My question is, given that as per the official docs, persistent runners are not recommended
Although not generally recommended, it’s possible to disable the
passing of the --ephemeral flag by explicitly setting ephemeral: false
in the RunnerDeployment or RunnerSet spec. When disabled, your runner
becomes “persistent”.
how can one leverage artifact caching when using this controller?
Where will the cache content will be stored in the k8s cluster, given that containers are ephemeral?
If you are not using the enterprise version, the caches will be handled by Github itself. I came across some similar problems at my self-hosted runner to create a cache for nodeJs, VueJs, and Java. Here's what I did:
VueJs (moving dist folder) (note the actions/upload-artifact#v3)
name: CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
build-web:
runs-on: self-hosted
container:
image: node:14
steps:
- uses: actions/checkout#v3
- name: Build shc-web
run: |
yarn config set cache-folder .yarn
yarn
yarn run build
- uses: actions/upload-artifact#v3
with:
name: dist-folder
path: dist/
registry-web:
runs-on: self-hosted
needs: ['build-web']
steps:
- uses: actions/checkout#v3
- uses: actions/download-artifact#v3
with:
name: dist-folder
path: dist/
- name: Configure AWS
uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login#v1
- name: Registry on AWS repository
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: shccp
run: |
docker build -t $REGISTRY/$REPOSITORY:3.1.x-$GITHUB_RUN_ID .
docker push $REGISTRY/$REPOSITORY:3.1.x-$GITHUB_RUN_ID
Also, I used two different jobs to handle the build. It could be done in only one so there was no need to upload/download the dist. Actually, that was precisely what I had to do in the NodeJs action. The node_modules is just too big to be uploaded.
NodeJS:
name: CI
on:
push:
branches: [ "stage" ]
pull_request:
branches: [ "stage" ]
workflow_dispatch:
jobs:
ci-api:
runs-on: self-hosted
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 14
- name: Build api
run: npm install
- name: Configure AWS
uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login#v1
- name: Registry on AWS repository
id: registry-aws
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: shcapi
run: |
docker build -t $REGISTRY/$REPOSITORY:3.1.x-$GITHUB_RUN_ID .
docker push $REGISTRY/$REPOSITORY:3.1.x-$GITHUB_RUN_ID
echo "::set-output name=image-tag::$REGISTRY/$REPOSITORY:3.1.x-$GITHUB_RUN_ID"
No cache is needed once it is done in a single job. That is a pretty nice feature of Github actions btw.
The Java cache, on the other hand, is handled by the following action:
name: CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
ci-etlv4:
runs-on: self-hosted
steps:
- uses: actions/checkout#v3
- uses: actions/setup-java#v3
with:
distribution: adopt-openj9
java-version: 8
cache: 'maven'
- uses: stCarolas/setup-maven#v4.4
with:
maven-version: 3.8.2
- name: Build ETLv4
run: |
echo ${{ secrets.SETTINGS_BASE64 }} | base64 -d > settings.xml
mvn --settings settings.xml --global-settings settings.xml clean package -DskipTests=true
- uses: docker/login-action#v2
with:
registry: "iad.ocir.io"
username: ${{ secrets.OCI_REGISTRY_USER }}
password: ${{ secrets.OCI_REGISTRY_PASSWORD }}
- uses: docker/setup-qemu-action#v2
- uses: docker/setup-buildx-action#v2
with:
driver: docker
- uses: docker/build-push-action#v3
with:
context: .
push: true
tags: XXXXX
The actions/setup-java#v3 can deal with the maven/gradle caches.
Hope it helps.

GitHub Actions fails with reading JToken from JsonReader error

I am trying to follow the How to use GitHub Actions build matrix to deploy artifacts to multiple servers tutorial. I have finished halfway through the tutorial, however, I get the following error when it builds the app.
Error when evaluating 'strategy' for job 'prepare-release-on-servers'. (Line: 53, Col: 17): Error reading JToken from JsonReader. Path '', line 0, position 0.,(Line: 53, Col: 17): Unexpected value ''
I have checked the JSON file for validation and gone through the deployment file countless times.
Here is the deploy-application.yml file.
name: Deploy Application
on:
push:
branches:
- main
jobs:
create-deployment-artifacts:
name: Create deployment artifacts
runs-on: ubuntu-latest
outputs:
deployment-matrix: ${{ steps.export-deployment-matrix.outputs.deployment-matrix }}
steps:
- uses: actions/checkout#v2
- name: Compile CSS and Javascript
run: |
npm install
npm run prod
- name: Configure PHP 8.0
uses: shivammathur/setup-php#v2
with:
php-version: 8.0
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml
- name: composer install
run: |
composer install --no-dev --no-interaction --prefer-dist
- name: Create deployment artifact
env:
GITHUB_SHA: ${{ github.sha }}
run: tar -czf "${GITHUB_SHA}".tar.gz --exclude=*.git --exclude=node_modules --exclude=tests *
- name: Store artifact for distribution
uses: actions/upload-artifact#v2
with:
name: app-build
path: ${{ github.sha }}.tar.gz
- name: Export deployment matrix
id: export-deployment-matrix
run: |
JSON="$(cat ./deployment-config.json)"
JSON="${JSON//'%'/'%25'}"
JSON="${JSON//$'\n'/'%0A'}"
JSON="${JSON//$'\r'/'%0D'}"
echo "::set-output name=deployment-matrix::$(echo $JSON)"
prepare-release-on-servers:
name: "${{ matrix.server.name }}: Prepare release"
runs-on: ubuntu-latest
needs: create-deployment-artifacts
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- uses: actions/download-artifact#v2
with:
name: app-build
Here is the JSON file.
[{"name":"server-1","ip":"216.656.30.240","username":"root","password":"sdddssafilgwzxcxvgvggfdassa","port":"22","beforeHooks":"","afterHooks": "","path": "/var/www/html" }]
I cannot find the problem here. Any help would be nice. Thanks in advance.
Maybe you should follow the instructions of Philo article link
This code is also running deprecated commands(set-output). so you need also not to use them anymore and use the new ones.
name: Set output
run:
echo "{name}={value}" >> $GITHUB_OUTPUT

How to create a dotenv file using Github Actions in the Deploy steps?

I'm learning CI CD to deploy REST API to VPS using Github Actions.
I am confused about how to make a dotenv file so that it is on the VPS server using Github Actions, because this REST API requires a Jsonwebtoken key and I have to insert it in the .env file. I've tried several ways but nothing works.
If you have the answer, please modify my .yml file below and include your answer so I can understand it clearly.
I really appreciate any answer.
name: Node.js CICD
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: create env file
run: |
touch .env
echo JWT_ACCESS_TOKEN_SECRET=${{ secrets.JWT_ACCESS_TOKEN_SECRET }} >> .env
- name: install and test
run: |
npm i
npm run build --if-present
npm run test
env:
CI: true
deploy:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: deploy with SSH
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
port: 22
script: |
cd ~/apps/routeros-api
git pull origin master
npm i --production
pm2 restart routeros-api

Github Action: [!] Error: Cannot find module 'rollup-plugin-commonjs'

In my package.json there are rollup and rollup-plugin-commonjs
but inside github actions it could not find those packages!
If I do not add rollup in global package installation step of github-action it shows that rollup is not found. But after adding both rollup and rollup-plugin-commonjs I get [!] Error: Cannot find module 'rollup-plugin-commonjs'
this is my workflow file:
name: Github Action
on:
push:
branches:
- fix/auto-test
jobs:
test:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout#v1
- name: Bootstrap app on Ubuntu
uses: actions/setup-node#v1
with:
node-version: '11.x.x'
- name: Install global packages
run: npm install -g prisma rollup rollup-plugin-commonjs
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache Project dependencies test
uses: actions/cache#v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install project deps
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Run docker
run: docker-compose -f docker-compose.test.prisma.yml up --build -d
- name: Sleep
uses: jakejarvis/wait-action#master
with:
time: '30s'
- name: Reset the database for safety
run: yarn reset:backend
- name: Deploy
run: yarn deploy:backend
- name: Build this great app
run: yarn build
- name: start app and worker concurrently and create some instances
run: |
yarn start &
yarn start:worker &
xvfb-run --auto-servernum yarn test:minimal:runner