error "gatsby-source-github-api" threw an error while running the sourceNodes lifecycle: token is undefined - github

I am new to Gatsby and just tried a GH Actions workflow for my site today. I see this error at the build stage:
error "gatsby-source-github-api" threw an error while running the
sourceNodes lifecycle: token is undefined
I am using this to pull all repos on my Github into the site.
What I have tried so far:
Checked the Github personal access token
the build is working locally
Versions:
"gatsby-source-github-api": "^0.2.1" "gatsby": "^2.26.1"
This is my node.js.yml GH Actions workflow file:
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [13.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
PS: I have used a .env file to hold the value of the token that the plugin 'gatsby-source-github-api' requires. And it is in my .gitignore file. So which means it is not sent to GH and hence can't find it?

So that was it -- the .env file which wasn't being pushed to Github.
So I needed to make the token available to the GH Action build somehow.
I tried the action SpicyPizza/create-envfile#v1. It isn't supported by Github but seemed to do the job. It creates a .env file at build with the keys you provide it.
You could also create a .env file manually. See thread.

Related

How do I setup a github `workflow.yml` for main, beta and dev branches to publish on microsoft azure?

The following workflow.yml works as expected when comitting changes to my main branch for our Flutter web based application.
name: Build and deploy Node.js app to Azure Web App - myApp
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Node.js version
uses: actions/setup-node#v1
with:
node-version: '12.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'myApp'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_MYAPP }}
package: .
But we are challenged to make the workflow to publish to an additional dev and beta branch, so that the website branches could be addressed like this:
main: myapp.azurewebsites.net
beta: beta.myapp.azurewebsites.net
dev: dev.myapp.azurewebsites.net
So how should the workflow.yml be to publish those two additional branches ?
Do I need to do some more in azure setting/enviroment or github to make it work ?
The branches in github are named 'main', 'beta' and 'dev'.

Updated Node version in GitHub Action not being picked up in PR checks

I have the following action set up in my private GitHub repo:
# 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: [14.17.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: yarn install --frozen-lockfile
- run: yarn test
Previously, the node-version was set to [15.x] and everything worked wonderfully. Since updating the required Node version to 14.17.x I have a check in my PRs that never resolves. It says:
build (15.x) Expected — Waiting for status to be reported Required
What am I missing here? It’s almost as if something is cached.
The issue ended up being a required status check that was added in “Settings » Branches » Require status checks to pass before merging » Require branches to be up to date before merging”. I removed that status check and re-added the updated version, then the message disappeared from the Checks list in all open PRs.

Github actions: Dependencies lock file is not found in runners/path

I have a single Github repository for both server and frontend. The directory structure looks like:
root
|- frontend
|- server (Express App)
Github Action:
name: Node.js CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
working-directory: './server'
- run: npm run start
working-directory: './server'
I only have a single job to build the Express server (and not the frontend yet) so I set the working-directory to ./server. However, I still get an error:
Dependencies lock file is not found in /home/{username}/runners.../repository_name. Supported file patterns: package-lock.json,yarn.lock
So apparently it's not trying to run in .../reposirtoy_name/server.
I'm just trying to build both server and frontend in single Github action.
There might be a chance that your problem is specifically with "uses: actions/setup-node". They mention in the docs that if you have multiple lock files or a lock file(s) in a directory that is not the root
In my case I had a single project with nested projects/dir. In my GitHub actions I wanted to run npm test on the nested project/dir so I had to specify to use my package.json inside the specific sub-directory. Double check to see that you are specifying the right directories with cache-dependency-path.
Specified here
https://github.com/actions/setup-node#caching-packages-dependencies
Try out this solution. It worked in my case.
In the build insert the default working directory
build:
runs-on: self-hosted
defaults:
run:
working-directory: ./server/
strategy:
matrix:
node-version: [14.x]
Then include cache dependency path. This should be the location of your package-lock.json file
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: './server/package-lock.json'
tldr
Make sure your checkout repo step is BEFORE setup node step, if using cache property with actions/setup-node#v3.
For me, it was caused by cache property on actions/setup-node#v3.
Without it - everything worked fine.
With it - failed. Reason is, it uses as cache key the package-lock.json (or yarn.lock) file.
See: https://github.com/actions/setup-node
My checkout repo step (actions/checkout#v2) was AFTER the setup node step, so it didn't find the package-lock.json file - because it wasn't checked out yet.

EACCES: permission denied, unlink '/home/runner/work/gos_front/gos_front/node_modules/.yarn-integrity

I have this workflow.yaml for github actions:
name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14]
steps:
- name: Checkout repository
uses: actions/checkout#v2
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
uses: borales/actions-yarn#v2.0.0
with:
cmd: install --ignore-engines
- name: Run linters
uses: borales/actions-yarn#v2.0.0
with:
cmd: lint:prettier
- name: Run cypress
uses: cypress-io/github-action#v2
with:
build: npm run build
start: npm start
- name: Build
uses: borales/actions-yarn#v2.0.0
with:
cmd: build
Then it runs, on run cypress occurs an error:
error An unexpected error occurred: "EACCES: permission denied, unlink
'/home/runner/work/gos_front/gos_front/node_modules/.yarn-integrity'"
.
Before that I add cypress run all was right. I tried to add sudo but it not helped. I use yarn.
cypress-io/github-action tries to install dependencies as well and runs into an access issue. The problem is the way your node_modules folder is created.
I ran into this when using Docker, mapping node_modules from inside the docker image to the outside. This is a known issue.
You use borales/actions-yarn. This is an outdated package, that probably does something similar. You should instead use yarn directly. From their readme:
Please keep in mind that this Action was originally written for GitHub Actions beta (when Docker was the only way of doing things). Consider using actions/setup-node to work with Yarn. This repository will be mostly supporting the existing flows.

How to replace a API key with a Secret in code during Github Actions Job?

I usually hide my API key in an XML file and use .gitignore along with getString() to retrieve my API key.
I'm trying to use Github Actions to automate Gradle build and Release of debug apk's. Due to the XML file not being uploaded to the repo, it obviously fails.
Is there any way to store my key in Github Secrets and then replace the code with the secret?
Current code: headers["token"]= getString(R.string.token)
Replaced code in Github actions server : headers["token"]="MY_API_KEY_FROM_SECRETS"
Here's my YAML file that I was using:
name: Gradle build test and release
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
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
#I'd like to replace the api key here in code from secrets
- name: Make Gradle executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Build Debug APK
run: ./gradlew assembleDebug
- name: Releasing using Hub
uses: ShaunLWM/action-release-debugapk#master
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
APP_FOLDER: app
RELEASE_TITLE: New Build
BODY: github.event.head_commit.message
prerelease: true
Sure, this is possible. You haven't said what file you'd like modified, but this should be easy enough to do with a one-liner (replacing FILENAME with your config file name):
- run: perl -pi -e 's/getString\(R\.string\.token\)/"$ENV{TOKEN}"/' FILENAME
env:
TOKEN: ${{ secrets.TOKEN }}
If you prefer Ruby or some other scripting language, you can use that instead. You could also use sed, but I prefer this approach because it means that the value is never available in ps output (even if this is a locked down VM).