Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github actions echo command not creating file

I'm in the process of moving a working CircleCI workflow over to Github Actions.

I'm running:

runs-on: ubuntu-latest

container: 
  image: google/cloud-sdk:latest

I run the following command:

echo ${{ secrets.GCLOUD_API_KEYFILE }} > ./gcloud-api-key.json

Before running this command, gcloud-api-key.json has not yet been created. This command works in CircleCI but in Github Actions I get the error:

/__w/_temp/asd987as89d7cf.sh: 2: /__w/_temp/asd987as89d7cf.sh: type:: not found

Does anyone know what this error means?

like image 683
bryan Avatar asked Nov 06 '19 01:11

bryan


People also ask

How do I echo an action in GitHub?

You should use run: echo "$GITHUB. REPOSITORY" and run: echo "$GITHUB. REPOSITORY_OWNER" to see them directly on your workflow. Tip: You can identify most of the variables that can be shown with echo through the Github Context using run: echo "$GITHUB_CONTEXT" in your workflow.

What does echo in Git do?

When echoing something to a file, >> appends to the file and > overwrites the file. From the example you posted, a log directory is created and then *. log is put into log/. gitignore so that no log files are committed to git.

What is $Github_env?

GITHUB_ENV. The path on the runner to the file that sets environment variables from workflow commands. This file is unique to the current step and changes for each step in a job.

Can GitHub Actions modify file?

A GitHub Action to push any local file changes, including new files, back to supplied branch name. This action is useful to put after other actions that modify files in the local checkout that you'd then like to persist back into the repository.


2 Answers

The reason was because my secret key was more then 1 line long. Once I made it one line it worked.

like image 101
bryan Avatar answered Jan 02 '23 23:01

bryan


In order to use secrets which contain more than just one line (like secret jsons) one has to save the base64 encoded secret in Github which makes it one line. On linux the encoding is done via:

cat mysecret.json | base64

Then in the action you need to decode it using

echo ${{ secrets.YOUR_SECRET }} | base64 -d > secret.json
like image 45
finisinfinitatis Avatar answered Jan 03 '23 01:01

finisinfinitatis