For the life of me I can't figure out why this yaml won't validate:
# This workflow will do a clean install of node dependencies, 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]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: >-
git config --global url."https://".insteadOf git://
- run: >-
git config --global url."https://github.com/".insteadOf git#github.com:
- run: npm ci
- run: npm run build --if-present
It gives me a Error : can not read an implicit mapping pair; a colon is missed at line 27 error which doesn't lead to any promising results.
Any help would be greatly appreciated!
YAML parser is picking up the second colon on line 27.
git config --global url."https://".insteadOf git://
You can escape the colon with format.
git config --global url."https://".insteadOf ${{ format('git{0}//', ':') }}
Related
I am making a Github workflow for testing a lambda function correctness.
Here is a snippet of the workflow config:
name: push-lambda
on:
push:
branches:
- main
env:
PYTHON_VERSION: "3.9"
defaults:
run:
shell: bash
jobs:
test_lambda:
runs-on: ubuntu-latest
steps:
- name: Install python
- uses: actions/setup-python#v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install bs4
run: pip install bs4
- name: Checkout repo
- uses: actions/checkout#v3
- name: Test function correctness
run: python function.py
(...)
However, I keep getting a
You have an error in your yaml syntax on line 20
error message. Line 20 is the first steps: keyword. Can anyone spot where I am making a mistake?
There is an indentation problem in your YAML at line 20, in the Install python step.
You're using:
jobs:
test_lambda:
runs-on: ubuntu-latest
steps:
- name: Install python
- uses: actions/setup-python#v4
with:
python-version: ${{ env.PYTHON_VERSION }}
Instead of:
jobs:
test_lambda:
runs-on: ubuntu-latest
steps:
- name: Install python
- uses: actions/setup-python#v4
with:
python-version: ${{ env.PYTHON_VERSION }}
The with field should be at the same level than the uses field.
I want to bump the version by running my shell script. I am manually triggering the GitHub Actions with inputs. I am using GitHub API to get the latest version and I want to run my shell script with the version taken from GitHub API.
I am able to achieve everything. It's just that I am not able to get the version output.
This is my GitHub Workflow:
#############################################################################
# GitHub Action to bump release version
#
#############################################################################
name: "Bump version and Update Milestone"
on:
workflow_dispatch:
inputs:
version:
description: 'New Version'
required: true
default: 'warning'
permissions:
contents: write
pull-requests: write
jobs:
printInputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "Latest Version: ${{ github.event.inputs.version }}"
bump:
name: Bump version
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout#v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get the version
id: get_version
run: |
VERSION=$(curl -s https://api.github.com/repos/checkstyle/checkstyle/releases/latest \
| jq ".tag_name")
echo VERSION="$VERSION"
- name: Modify File
run: |
./.ci/bump-version.sh ${{ steps.get_version.VERSION }}
- name: Push commit
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]#users.noreply.github.com'
git commit -am "minor: Bump release version to ${{ steps.get_version.VERSION }}"
git push
- name: GitHub Milestone
run: |
.ci/update-github-milestone.sh
This is my shell script:
#!/bin/bash
set -e
VERSION=$1
echo VERSION="$VERSION"
echo "bump version in pom.xml"
mvn versions:set -DnewVersion="$VERSION" && mvn versions:commit
And these is my tested actions where I want help:
Action link: https://github.com/Rahulkhinchi03/checkstyle/runs/7785606554?check_suite_focus=true
To transfer an output from one step to another, you need to use a workflow command:
echo "::set-output name=VERSION::$VERSION"
and then reference it like this in a later step via the outputs object:
run: |
./.ci/bump-version.sh ${{ steps.get_version.outputs.VERSION }}
I want to access env variables in my .env. But of course, we can't commit the .env file.
So I've added an action secret to my Github called MONGODB_PASSWORD. But when I tried to access that secret, it's not working as expected.
Any thought on how I can do this?
This is what I have in my .yml
name: Node.js CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
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'
env:
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} // Setting the secret here
- run: npm ci
- run: npm run build --if-present
- run: npm run lint
- run: npm run test
- run: npm run test:e2e
Try setting env on job level instead of step level:
name: Node.js CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
env:
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} // Setting the secret here
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
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 run lint
- run: npm run test
- run: npm run test:e2e
I'm trying to make GitHub CI
What's wrong with this formatting?
I have such a problem
Invalid workflow file
You have an error in your yaml syntax on line 8
screenshot of error
name: Chart project CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
check-links:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [17.x]
steps:
uses: actions/checkout#v3
- name: Starting Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
- name: install modules
- run: npm install
- name: build project
- run: npm build
- name: unit test
- run: npm test
Additional info
There are some indentation and syntax issue. Please find the correct code below. Here you can find a sample run. Link
name: Test CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
check-links:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [17.x]
steps:
- uses: actions/checkout#v3
- name: Starting Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
- name: install modules
run: npm install
- name: build project
run: npm build
- name: unit test
run: npm test
Is it possible to access a github secret in a yaml file that's not a workflow or an action yaml file?
For example, I've saved in github the environment secret INFURA_RINKEBY_WSS and I attempt to access it in the following yaml config file for my program.
type: EndpointList
endpoints:
- type: RPCEndpoint
chain_id: 1
network: rinkeby
provider: Infura
url: ${{ secrets.INFURA_RINKEBY_WSS}}
explorer: https://etherscan.io
However, the INFURA_RINKEBY_WSS environment variable I've set in github isn't accessed yet by my yaml config file.
The following is my main.yaml github workflow:
name: Report to eth/usd on rinkeby w/ pytelliot
on: push
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout#v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install telliot-feed-examples
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Move pre-made pytelliot configs to home directory
run: |
cp -r ./config ~/
- name: report :)
run: telliot-examples --legacy-id 1 report --submit-once
env:
PK: ${{ secrets.PK }}
INFURA_RINKEBY_WSS: ${{ secrets.INFURA_RINKEBY_WSS }}
Thanks!