Github actions multiple environments and multiple runners - github

I have two separate EC2 instances. One for dev and one for production.
I am hosting a backend RESTapi.
I created a production.yml file
name: Live backend
on:
push:
branches: [ main ]
pull_request:
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 }}
- run: rm package-lock.json
- run: npm i
- run: pm2 restart app.js
and connect this to a runner and everything is working fine.
If I add another development.yml file and a runner.
How should I specify first AWS instance runs the only production and the second AWS instace runs only dev?
Hope my question is clear.
Any help!
Thanks in advance. =D

Related

Github actions PM2 start command not starting process

I'm facing issue with PM2 start. when i push code to master branch all below steps working correctly without any issue. but when i login to my EC2 using SSH and check for pm2 list there is no process showing.
I've google a lot but didn't get any working solution.
Below is my workflows yml file
name: Node.js CI
on:
push:
branches: [ "master" ]
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#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: pwd
- run: npm ci
- run: npm run build --if-present
- run: pm2 kill
- run: echo 'pm2 process killed successfully'
- run: pm2 start dist/main.js
- run: pm2 list

Github Actions - Cypress

I followed official Cypress documentation, and below I will attach my github workflow, but problem is it goes different way in my case. When actions run, Cypress starts downloading something, but it never ends (I waited 1.5 hour).
env:
NODE_PATH: 'src/'
#.. local env
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [ 14.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: npm ci
- name: Server start
uses: cypress-io/github-action#v2
with:
build: npm run build
start: npm start
spec: cypress/integration/*.js
env:
ELECTRON_ENABLE_STACK_DUMPING: 1
- name: Exist check
# Only runs if all of the files exists
run: |
if [ -d "/..." ]
then
rm -r /...
mv build /...
fi
Problem is old version of ubuntu. change version or mention it in yaml.

Github actions how to configure two runners in two servers

I have a GitHub repo called api.
api has two branches DEV and QA
I have set up a workflow for the DEV branch and worked correctly.
This is the workflow for DEV branch
# This workflow will do a clean install of node dependencies, cache/restore them, 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: [DEV]
pull_request:
branches: [DEV]
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
# - run: pm2 stop app.js
- run: pm2 start ecosystem.config.js --update-env
Then I created my second EC2 instance and second runner and another workflow file
# This workflow will do a clean install of node dependencies, cache/restore them, 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: QA Build
on:
push:
branches: [ QA ]
pull_request:
branches: [ QA ]
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 i
- run: pm2 start ecosystem.config.js --update-env
But whenever I push some code to the QA branch still my first runner runs and first EC-2 instance. Seems the second instance or workflow doesn't use at all.
How do I specify the runner and the instance based on the branch?
If you just have two runners with the default setup, you will not be able to differentiate between the two. As such a job just takes any of the two.
A label can mark one specific runner, which you can then choose directly. See the GitHub self-hosted runners docs on labels
You can then use the specific runner like this
runs-on: [self-hosted, dev]

github action runner showing "idle" and not updating the main website

I have been using DigitalOcean: if I change or commit repository the website not being updated.
I am using just one master branch, I had 23 file changes but on the site no effects.
here is my action code:
name: Node.js CI
on:
push:
branches: [ master ]
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 i
- run: npm run build --if-present
- run: npm test
if I change or commit repository the website not being updated.
I am using just one master branch,
First, a change or commits are local actions: you need to push (git push) to GitHub in order for any action to have a chance to run.
Second, assuming that you have pushed, but your workflow was not triggered, add a on: directive (that you have) and double-check your default branch: recent repositories are using main, not master.
You can see an example in the official GitHub documentation "Building and testing Node.js / Starting with the Node.js workflow template":
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
Third, if you need to see some effect on a DigitalOcean Droplet, you might need to use digitalocean/action-doctl, in order to deploy (to DigitalOcean) what your GitHub action has build on GitHub side.

GitHub Actions unable to load via SSH despite it appearing to work using ssh-access

I am working on a github action to runs tests on my PRs and pushes but I am having trouble ensuring that the tests are able to access my private repos.
I have tested the SSH credentials I am using locally and they 100% work.
https://github.com/webfactory/ssh-agent
Here is the SSH agent I am using.
and here is my github action
# 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:
- master
- release/*
pull_request:
branches:
- master
- release/*
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout#v2
- uses: webfactory/ssh-agent#v0.4.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- 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 --if-present
- run: npm test
It appears to be making no attempt to utilize the SSH keys that it is getting
Since https://github.com/Tixpire/tixpire-server seems to be private, you will need to use a PAT (personal access token) to access it.
See also actions/checkout issue 95.
It is an HTTPS URL, so no amount of SSH keys will work: you would need an SSH URL for that (git#github.com:Tixpire/tixpire-server)