Why is the checkout of a private repository on GitHub Actions returning "Error : fatal: could not read Username for 'https://github.com'"? - github-actions

The project's local development environment makes it mandatory to have a .npmrc file with the following content:
registry=https://registry.npmjs.org/
#my-organization:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=your-GitHub-token-should-be-here-and-I-will-not-share-my-for-security-reasons
Hence, any client properly authenticated into the GitHub Packages
Registry can install our private NPM packages hosted for free on GitHub Registry by running:
npm ci #my-organization/our-package
Ok, it works on my local development environment.
Now, I am building a Continuous Integration process with GitHub Actions which is a different but similar challenge. I have this on my .yaml file:
- name: Create .npmrc for token authentication
uses: healthplace/npmrc-registry-login-action#v1.0
with:
scope: '#my-organization'
registry: 'https://npm.pkg.github.com'
# Every user has a GitHub Personal Access Token (PAT) to
# access NPM private repos. The build of GitHub Actions is
# symmetrical to what every developer on the project has to
# face to build the application on their local development
# environment. Hence, GitHub Actions also needs a Token! But,
# it is NOT SAFE to insert the text of a real token on this
# yml file. Thus, the institutional workaround is to insert
# the `{{secret}}` below which is aligned/set in the project
# settings on GitHub!
auth-token: ${{secrets.my_repo_secret_key_which_is_not_being_shared}}
On GitHub settings->secrets->actions->"add secret":
On the secret value, I added the same content I have on .npmrc.
I was expecting it to work. Unfortunately, an error message is retrieved:
Error: fatal: could not read Username for 'https://github.com': terminal prompts disabled
Why is that so?

I made the mistake of adding all the content on my .npmrc.
It is wrong. And GitHub already knows some things, such as the scope. #my-organization.
Hence, the solution is only adding the following snippet (using the example provided on the question):
your-GitHub-token-should-be-here-and-I-will-not-share-my-for-security-reasons
And it works as expected :)

Related

elastic beanstalk document root resolves to /var/www/html/var/www/html/

I want to deploy a laravel site using elastic beanstalk.
I'm using pipelines pulling from a BitBucket repository.
After I created my EB application and environment, I changed the document-root to /web/public because the laravel-root is under the '[repo-root]/web' directory.
The deployment is failing:
2023/02/12 01:40:11 [error] 3857#3857: *109 "/var/www/html/var/www/html/web/public/index.php" is not found (2: No such file or directory), client: ..., server: , request: "GET / HTTP/1.1", host: "..."
A similar project where the laravel-root === 'repo-root' and document-root: public works, but this is not ideal.
How can I configure the pipeline or EB to use the '[repo-root]/web' as the document-root?
I've unsuccessfully tried various values for the document-root, but nothing seems to work.
In another forum, someone suggested changing the pipeline to return the laravel-root as an artifact, but I'm not sure how to do this. Seems like it is stored as a zip under S3 and if I change to Full Clone I get an invalid-structure error related to code build. I don't know what that means since I'm not using code build.
TIA
While I'm sure there are a number of ways to solve this, what worked for me was using CodeBuild to pull the code from the repo and a buildspec.yml file to create a zip of just the directory required for deployment.
buildspec.yml
version: 0.2
phases:
pre_build:
commands:
- cd web
- zip -r ../web.zip ./*
artifacts:
files:
- web.zip
Still under CodeBuild, I configured the Artifacts to output to an S3 bucket. Then I created a Code Pipeline with a Source stage that pulls the zip from the build bucket and a Deploy stage that sends the source artifact to Elastic Beanstalk (provider). When setting up the pipeline, it seems to want you to have a 'Build' stage between Source and Deploy, but I deleted this.
It looks like you can also leverage artifact handling and let CodeBuild do the packaging (zipping). I haven't tested this. https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.artifacts.base-directory
...
artifacts:
files:
- '**/*'
base-directory: 'my-build*'
As far as the weird pathing issue in the original post, I think there was some sort of EB config cache issue/corruption. When I rebuilt the environment, that error was gone.

Endless Waiting for a runner to pick up this job in github enterprise

EDIT: My repo resides in github enterprise
I have a very basic github workflow action as below:
All it does is to run a powershell script as mentioned in here.
name: First Github Action
on:
workflow_dispatch:
jobs:
first-job:
name: First Job
runs-on: ubuntu-latest
steps:
- name: Display the path
run: echo ${env:PATH}
shell: pwsh
Unfortunately, it just keeps waiting for the runner to pick up. Below is the message it is being displayed.
Requested labels: ubuntu-latest
Job defined at: {myUserName}/{repoName}/.github/workflows/{myFileName}.yml#refs/heads/main
Waiting for a runner to pick up this job...
EDIT: I created another public repo and ran the action. It is still waiting.
Unfortunately, I cannot share my public repo as it is an enterprise github repo owned by the company I work in.
Assuming you are running this on GitHub Cloud (or github.com):
GitHub Actions is only free for public repositories, otherwise you have to pay for a license
Switching the repo's visibility from from private to public may not cause the workflow that is stuck to be picked up. You will likely need to cancel it and queue a new one.
Make sure your workflows are located in .github/workflows folder.
Assuming you are running this on GitHub Enterprise Cloud (GHEC):
You need to make sure that your admin has Actions enabled
You need to make sure that your admin has Actions allowed for repositories not owned by an organization
Assuming you are running this on GitHub Enterprise Server (GHES):
You need to make sure that your admin has Actions enabled
You need to make sure that your admin has Actions allowed for repositories not owned by an organization
You will not be able to use GitHub hosted runners as you have in your YAML file
You will need to use a self-hosted runner and your GitHub admin can provide you the details of what you need to use.
The workflow you have in your question does in fact work:
https://github.com/tjc-actions-demo/simple-actions
The issue is going to be either permissions related or configuration related. Depending on your environment, you will need to troubleshoot based on my suggestions above.

How to add additional permissions to custom steps in GitHub Actions

I have two steps in GitHub Actions:
The first uploads a zipped artifact:
- name: Upload artifact
uses: actions/upload-artifact#master
with:
name: artifacts
path: target/*.jar
The second uses a custom java command to read the uploaded artifact:
name: Read artifact
runs: java -jar pipeline-scan.jar -- "artifacts.zip"
I've redacted the java command, but it's supposed to scan my zip file using Veracode. GitHub Actions returns the following error:
java -jar pipeline-scan.jar: error: argument -f/--file: Insufficient
permissions to read file: 'artifacts.zip'
I've tried changing the permissions of the GITHUB_TOKEN, but apparently you can only pass in the $GITHUB_TOKEN secret with a "uses" parameter and not a "runs" parameter. I've also made sure that my default workflow permissions are set to "read and write permissions."
Does anyone know how to resolve this permissions issue?

v3 where to get git_url?

I am trying to clone to my local git repository.
From Mac terminal:
git clone git_url directory_to_create
In the web console, I tried to use the GitHub Webhook URL and Generic Webhook URL. But I got this error: The requested URL returned error: 405
Any suggestions?
OpenShift doesn't host a Git repository for you. It relies on you having a separate hosted Git repository to pull application source code from. Alternatively, you can use a binary input build and push source code from your local system.
If you already have a deployed application how did you create it?
If it was a sample S2I application, you need to go to GitHub where the source code for that sample application was and clone it into your GitHub account. You can then check it out from your fork in your own GitHub account to your local system. You will though need to update the build configuration for the application in OpenShift to then use your fork of the original sample application.

How to perform automatic cloning of github repository and that repository should be copied in one folder automatically using node js..?

How to perform automatic cloning of github repository and that repository should be copied in one folder automatically using node js..??
I have used this link http://www.nodegit.org/ and followed all the steps to clone the repository which are given here..but still getting these two error.
%1 is not a valid windows 32 application and Failed to load resource: the server responded with a status of 500 internal Servor error.
Any help will greatly be appreciated..??
I create a ruby library that allow anyone to clone multiple Github repository easily in one simple command using your own credential.
If you have ruby install then you could run something like
$gem install github-cloner
$github-cloner --user awesome_user
--base-dir ~/Desktop/github
--languages "JavaScript"
--clone
Detail installation and sample usage are in the README.md of the project.