GitHub Actions fails with reading JToken from JsonReader error - github

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

Related

I can't able to upload an artifact to GitHub

there I am facing some issues with my workflow artefacts. The Error is
-(Error: Create Artifact Container failed: Artifact storage quota has been hit. Unable to upload any new artifacts )
I create a zip and then upload it to artefacts does not work. and I delete my old artefacts still I'm facing this issue. I tried so many ways to upload artefacts but nothing worked for me.
I'm sharing my workflow:
name: Build and Deploy My App
on:
push:
branches: [master]
workflow_dispatch:
jobs:
build:
name: Creating Build ⚒
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout#main
- name: setup Node Version To 16
uses: actions/setup-node#v2
with:
node-version: '16.x'
- name: Installing Packages 📦
run: npm install --legacy-peer-deps
- name: 🔨 Build Project
run: CI=false npm run build
- name: zip the build folder
run: zip release.zip ./build/** -r
- name: Archive production artifact
uses: actions/upload-artifact#v3
with:
name: my-app-build
path: release.zip
deploy:
name: Start The Deploying 🚀🤘
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact#v3
with:
name: my-app-build
- name: unzip the build folder
run: unzip my-app-build
- name: All Good To Go ✔ start Sync files to hosting
uses: SamKirkland/FTP-Deploy-Action#4.3.3
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}

Github actions: Re-usable workflows

So what I am trying to do is to organize my ci workflow. I have a self-hosted runner that is my personal computer. Since the workflow files is getting too large I am thinking about reducing the size by having different workflow files instead.
so this is my files so far:
name: "Pipeline"
run-name: ${{ github.actor }} just pushed.
on:
schedule:
- cron: "0 2 * * *"
push:
branches-ignore:
- "docs/*"
tags:
- "v*"
workflow_dispatch:
inputs:
cc_platform:
description: "Input of branch name to build metalayers."
required: true
default: "dev"
jobs:
build:
runs-on: self-hosted
name: Build job.
steps:
- name: Checking out the repository.
uses: actions/checkout#v3
- name: Settings Credentials.
uses: webfactory/ssh-agent#v0.6.0
with:
ssh-private-key: ${{ secrets.SSH_KEY_CC }}
- name: Creating config file.
run:
touch conf
- name: Removing old folders & running build script.
run: |
if [[ -d "my_folder" ]]; then rm -rf my_folder; fi
./build
- name: Generate a zip file of artifacts.
uses: actions/upload-artifact#v3
with:
name: art_${{ github.sha }}
path: |
.*.rootfs.wic.xz
.*.rootfs.manifest
if-no-files-found: error
so what I want to do it to have the artifacts and the build step in their own workflow file. But it does give me som concersn.
Will each workflow file get run in their own runner?
Do they share memory?

Unable to use secrets in workflow

We have a project from the previous agency that uses GitHub actions.
I already tried several attempts but unfortunately, I was not able to solve the problem.
I am stuck at Unrecognized named-value: 'secrets'. Located at position 1 within expression: error.
Here is the action.yml
name: Create envfile
on: [ push ]
jobs:
create-envfile:
runs-on: ubuntu-latest
steps:
- name: Make envfile
with:
envkey_DEBUG: false
envkey_CLIENT_ID: ${{ secrets.CLIENT_ID }}
envkey_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
directory: projectName/
file_name: .env
fail_on_empty: false
And the part of workflow.yml where the build process stops executing
on:
push:
branches:
- main
workflow_dispatch:
jobs:
flake8-lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout#v2
- name: Set up Python environment
uses: actions/setup-python#v2
with:
python-version: "3.10"
- name: flake8 Lint
uses: py-actions/flake8#v2
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: ./.github/actions/create_envfile // it stops here
- name: Set up Python version
uses: actions/setup-python#v1
with:
python-version: '3.8'
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt
It stucks in - uses: ./.github/actions/create_envfile part in the workflow
Here is the full error
Error:
/home/runner/work/projectName/./.github/actions/create_envfile/action.yml (Line: 16, Col: 27):
Error: /home/runner/work/projectName/./.github/actions/create_envfile/action.yml (Line: 17, Col: 31):
Error: /home/runner/work/projectName/./.github/actions/create_envfile/action.yml (Line: 16, Col: 27): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.CLIENT_ID
Error: /home/runner/work/projectName/./.github/actions/create_envfile/action.yml (Line: 17, Col: 31): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.CLIENT_SECRET
Error: Fail to load /home/runner/work/projectName/./.github/actions/create_envfile/action.yml
Any ideas how to fix this?
This is because composite actions do not have access to the "secrets" namespace for security reasons. They do have access to the environment variables set by the calling workflow or you can pass in secrets as inputs to the action.
From your comments all you need to do is use the action from the marketplace and not store as your own composite action like so:
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: SpicyPizza/create-envfile#v1.3.0
with:
envkey_DEBUG: false
envkey_CLIENT_ID: ${{ secrets.CLIENT_ID }}
envkey_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
directory: projectName/
file_name: .env
fail_on_empty: false
- name: Set up Python version
uses: actions/setup-python#v1
with:
python-version: '3.8'
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt

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

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

github action failing? tar empty archive, docker run failed with exit code 1

This is the project structure:
- parent/
|- .github/workflows/
|- frontend/
|- ...
This is the .yml file within workflows:
name: CI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-node#v1
with:
node-version: "12.x"
- name: Install dependencies
working-directory: frontend
run: npm install
- name: Build
working-directory: frontend
run: npm run build
- name: Deploy Files
uses: appleboy/scp-action#master
env:
HOST: ${{ secrets.aws_pull_host }}
USERNAME: ${{ secrets.aws_pull_username }}
KEY: ${{ secrets.aws_pull_private_key }}
with:
working-directory: frontend
source: build/
target: "/home/build/site/testDir/"
strip_components: 1
Whenever the action gets to the step Deploy Files, i get the error:
tar: empty archive
tar all files into /tmp/891353322/bC24rHhFAi.tar
exit status 1
##[error]Docker run failed with exit code 1
First time working with github actions so I am pretty lost with this error. Appreciate any help.
Kept messing with it, finally figured it out:
- name: Deploy Files
uses: appleboy/scp-action#master
env:
HOST: ${{ secrets.aws_pull_host }}
USERNAME: ${{ secrets.aws_pull_username }}
KEY: ${{ secrets.aws_pull_private_key }}
with:
source: frontend/build/
target: "/home/build/site/testDir/"
strip_components: 1