composite github action, automatically cd into actions directory? - github-actions

I am trying to setup a github actions bot that uses composite to build when the action runs. Notably, this isn't required, and I know that ncc would also achieve the same thing, but I'm curious if it's possible to make this work in a sustainable way.
For some context, I'm trying to run my alita-moore/EIP-Bot private action with the yaml script being...
name: "Auto Merge EIP"
description: "A bot that lints EIP edits, finds common errors, and can auto-merge"
inputs:
GITHUB-TOKEN:
description: |-
The Github token to be used by this bot when merging, posting comments, or requesting reviewers
required: true
VERSION:
description: version of the action; this is required because of how actions work
required: true
runs:
using: "composite"
steps:
- run: cd /home/runner/work/_actions/alita-moore/EIP-Bot/${{ inputs.VERSION }} && npm ci && npm run build && GITHUB_TOKEN=${{ inputs.GITHUB-TOKEN }} node build/index.js
shell: bash
And this currently runs with a given repo's workflow yaml being
on: [pull_request]
jobs:
auto_merge_bot:
runs-on: ubuntu-latest
name: EIP Auto-Merge Bot
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Node.js Enviornment
uses: actions/setup-node#v2
with:
node-version: '14'
- name: auto-merge-bot
uses: alita-moore/EIP-Bot#1.0.8
id: auto-merge-bot
with:
GITHUB-TOKEN: ${{ secrets.TOKEN }}
VERSION: 1.0.8
You may have noticed that before the npm ci && npm run build I first had to cd /home/runner/work/_actions/alita-moore/EIP-Bot/${{ inputs.VERSION }}
If you don't do this it'll throw the following error
Run alita-moore/EIP-Bot#1.0.1
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/EIPs/EIPs/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/EIPs/EIPs/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-03-14T09_02_26_002Z-debug.log
Error: Process completed with exit code 254.
Is there a better way to do this?

You can use ${{github.action_path}} for the path of the directory containing the action definition file action.yaml:
[...]
runs:
using: "composite"
steps:
- run: cd ${{github.action_path}} && npm ci && npm run build && GITHUB_TOKEN=${{ inputs.GITHUB-TOKEN }} node build/index.js
shell: bash
github.action_path | string | The path where your action is located. You can use this path to easily access files located in the same repository as your action. This attribute is only supported in composite run steps actions.
https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context

The value for ${{ github.action_path }} is also available by default as the environment variable GITHUB_ACTION_PATH, so something like this is also an option:
[...]
- uses: actions/setup-python#v4
with:
python-version: '3.9'
- name: install-dependencies
run: pip install -r $GITHUB_ACTION_PATH/requirements.txt
shell: bash
This assumes the requirements.txt file is at the root of my composite actions directory.

Related

Backstage Unable to use mkdocs to create Tech Docs for an existing component

I have enabled Github actions to create Tech docs after a commit. Below is the workflow file written to create Md files. But "techdocs-cli generate --no-docker --verbose" command fails with the below error. Can someone please help with the issue?
Failed to generate docs from /home/runner/work/myapp3/myapp3 into /home/runner/work/myapp3/myapp3/site; caused by unknown error 'Command mkdocs failed, exit code: 1'
workflow file:
name: Publish TechDocs Site
on:
push:
branches: master
jobs:
publish-techdocs-site:
runs-on: ubuntu-latest
env:
TECHDOCS_S3_BUCKET_NAME: XXX
AWS_ACCESS_KEY_ID: XXX
AWS_SECRET_ACCESS_KEY: XXX
AWS_REGION: XXX
ENTITY_NAMESPACE: 'default'
ENTITY_KIND: 'Component'
ENTITY_NAME: ‘XXX’
steps:
- name: Checkout code
uses: actions/checkout#v2
- uses: actions/setup-node#v2
- uses: actions/setup-python#v2
- name: Install techdocs-cli
run: sudo npm install -g #techdocs/cli
- name: Install mkdocs and mkdocs plugins
run: python -m pip install mkdocs-techdocs-core==1.*
- name: Generate docs site
run: techdocs-cli generate --no-docker --verbose
- name: Publish docs site
run: techdocs-cli publish --publisher-type awsS3 --storage-name $TECHDOCS_S3_BUCKET_NAME --entity $ENTITY_NAMESPACE/$ENTITY_KIND/$ENTITY_NAME
I had the same issue and it was resolved once you had the right folder structure where you have the mkdocs.yml file.
As long as you have a docs folder in the same root structure with the .md file that needs to be published.
The same .md file needs to be configured in the navigation section of the mkdocs.yml file as well

lerna publish not working in GitHub Actions

We have a monorepo that we are using Lerna to publish to a private package manager (nexus). When the action runs, it fails with same vague message:
info cli using local version of lerna
lerna notice cli v5.3.0
lerna info ci enabled
Error: Process completed with exit code 1.
This message occurs after github actions tries to run the lerna publish command.
I've tried dozens of variations of installing Lerna globally and locally as well as all sort of variations of flags on my lerna bootstrap and lerna publish commands. I am not sure what to try. Any insights would be appreciated. Below is my worklflow file.
Node: 16.15.1
Lerna: 5.3.0
release.yml
name: 'MyPackage Production Release'
on:
workflow_dispatch:
inputs:
version:
required: true
type: choice
description: Which version should be published?
options:
- patch
- minor
- major
tag:
required: true
type: choice
description: Which npm tag should this be published to?
options:
- latest
- next
- test
jobs:
build-my-package:
runs-on: [self-hosted, Linux, X64, enterprise]
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0 #indicates all history for all branches and tags.
- uses: actions/setup-node#v3
with:
node-version: 16.15.1
registry-url: 'https://registry.npmjs.org'
- name: Configure Identity
run: |
git config user.name github-actions
git config user.email github-actions#github.com
shell: bash
- name: strict SSL
run: |
npm config set cafile my-file.pem
npm config set strict-ssl false
npm config set https-proxy http://proxy.our.proxysite.net:80/
npm config set proxy http://proxy.our.proxysite.net:80/
npm config set NODE_TLS_REJECT_UNAUTHORIZED=0
npm config set registry https://registry.npmjs.org/
- name: Install Dependencies
run: |
npm ci --no-package-lock --legacy-peer-deps
lerna bootstrap --ignore-scripts -- --legacy-peer-deps
shell: bash
- name: Prepare Nexus Token
run: |
npm config set registry https://nexus.our.site.net/repository/my-package-repo/
npm config set email myemail#myemail.net
npm config set strictSSL false
npm config set alwaysAuth true
echo //nexus.our.site.net/repository/my-package-repo/:_auth=${{ secrets.NEXUS_BASE64_AUTH }} > .npmrc
npm config set _auth ${{ secrets.NEXUS_BASE64_AUTH }}
shell: bash
- name: Release
run: |
HUSKY_SKIP_HOOKS=1 lerna publish $(echo "${{ github.event.inputs.version }}") --yes --force-publish='*' --dist-tag $(echo "${{ github.event.inputs.tag }}") --conventional-commits --create-release github
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GHE_API_URL: ${{ secrets.GHE_API_URL }}
GHE_VERSION: ${{ secrets.GHE_VERSION }}
shell: bash

facing a permission issue when build react app in GitHub actions

This is my GitHub Actions script to build a react project:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 14
- name: Install yarn
uses: borales/actions-yarn#v2.1.0
- name: Build React App
run: |
sudo rm -rf node_modules
yarn
umi build
when I run this project in GitHub actions, shows error:
warning "umi-serve > #babel/preset-typescript#7.3.3" has unmet peer dependency "#babel/core#^7.0.0-0".
warning "umi-serve > #babel/register#7.4.4" has unmet peer dependency "#babel/core#^7.0.0-0".
warning Workspaces can only be enabled in private projects.
warning Workspaces can only be enabled in private projects.
[5/5] Building fresh packages...
error An unexpected error occurred: "EACCES: permission denied, open '/home/runner/work/admin/admin/yarn.lock'".
info If you think this is a bug, please open a bug report with the information provided in "/home/runner/work/admin/admin/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Process completed with exit code 1.
why could not access the project yarn.lock when using yarn command? why facing the permission issue in GitHub Actions? what should I do to fix this problem?
I also facing the similar issue with it, you should tried to use actions/setup-node like this to fix it:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
- run: npm install yarn -g
- name: Build React App
run: |
yarn
yarn global add umi
umi build

Github - getting not found error when trying to publish package to npm

I'm trying to publish a new package to npm, public.
I have the following workflow:
# This workflow will run tests using node and then publish a package to GitHub
Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
name: Node.js Package
on:
release:
types: [created]
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm login
- run: npm config set access public
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
But I get the following error:
npm notice
npm notice 📦 #orgname/pdf-image#1.2.2
npm notice === Tarball Contents ===
npm notice 135B Dockerfile
npm notice 135B Dockerfile12
npm notice 1.1kB LICENSE
npm notice 6.8kB index.js
npm notice 5.9kB tests/test-main.js
npm notice 530B package.json
npm notice 2.1kB README.md
npm notice 325.2kB tests/test.pdf
npm notice 1.1kB .github/workflows/node.js.yml
npm notice 664B .github/workflows/npm-publish.yml
npm notice === Tarball Details ===
npm notice name: #orgname/pdf-image
npm notice version: 1.2.2
npm notice package size: 322.6 kB
npm notice unpacked size: 343.6 kB
npm notice shasum: d362e3a6c95d12b2329ed608495c45580bb8de15
npm notice integrity: sha512-OpurprtbmR7By[...]V553ykjYtaOrA==
npm notice total files: 10
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/#orgname%2fpdf-image - Not found
npm ERR! 404
npm ERR! 404 '#orgname/pdf-image#1.2.2' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
Please advise how can I resolve this issue.
npm login is unnecessary here.
You need to do 3 steps to make it work:
Config the job on your yml file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Define NPM_TOKEN access token in your npmjs account under access tokens, make sure it's an automation token:
Copy this token and define him in your GitHub repository:

npm ci command fails in GitHub actions when running on Node 16

I'm running npm ci on Node 16 in GitHub workflow actions and keep getting the following error:
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-01-10T11_38_28_617Z-debug.log
Error: Process completed with exit code 1.
I tried deleting the package-lock.json file and running npm i locally and uploading the new file. But it did not make a difference.
Workflow file
name: Node.js CI
on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Build the Docker image and run tests
uses: actions/checkout#v2
- run: npm ci
- run: npm test
Please advise how I can resolve this.
Looks like some of the packages in your package-lock.json file are in private registries.
You need to login to that registry as it is saying in the error. Otherwise NPM cannot pull those packages.