GitHub Alert: Invalid format for environment variable

I am facing an issue with GitHub action. Despite configuring the README.md via a web browser, I encountered an error in GitHub action:

Run export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
  export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
  echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
  shell: /usr/bin/bash -e {0}
Error: Unable to process file command 'env' successfully.
Error: Invalid environment variable format 'Indicate that a variable can have the value `null`. Null-Safety is default from version **2.12.0** in the Dart language.'

The error message seems related to the text within the README.md, and regardless of any edits made, it continues to display the same old error. I attempted to search for a solution online but couldn't find anything similar.

  • My current variable format is as follows:

Null-Safety is enabled by default, indicating that a variable may contain a null value. This change is mandatory in the new Dart language starting from version 2.12.0.

Below is my workflow file:

name: release master branch

on:
  push:
    branches:
      - master

jobs:
  build:
    name: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: install dependencies
        run: npm install
      - name: install vsce
        run: sudo npm install -g vsce
      - name: extract version number
        run: |
          export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
          echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
      - name: package the extension
        run: vsce package
      - name: release package to github repo
        uses: marvinpinto/action-automatic-releases@latest
        with:
          repo_token: '${{ secrets.GITHUB_TOKEN }}'
          automatic_release_tag: master-v${{ env.BUILD_VERSION }}
          prerelease: true
          title: 'Json to Dart Extension master-v${{ env.BUILD_VERSION }}'
          files: |
            ./json-to-dart-${{ env.BUILD_VERSION }}.vsix

Adding paths ignore does not seem to fix the issue.

on:
  push:
    branches:
      - master
    paths-ignore:
      - '**/README.md'

You can access the full code publicly on this repository: https://github.com/hiranthaR/Json-to-Dart-Model

Here's a partial log snapshot:

...
2021-08-02T19:38:38.3085331Z ##[group]Run sudo npm install -g vsce
2021-08-02T19:38:38.3086141Z [36;1msudo npm install -g vsce[0m
2021-08-02T19:38:38.3129504Z shell: /usr/bin/bash -e {0}
2021-08-02T19:38:42.3974877Z /usr/local/bin/vsce -> /usr/local/lib/node_modules/vsce/out/vsce
2021-08-02T19:38:42.4134841Z + <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b5d58484e6b1a05121d051a">[email protected]</a>
2021-08-02T19:38:42.4135550Z added 73 packages from 42 contributors in 3.582s
2021-08-02T19:38:42.4443780Z ##[group]Run export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
2021-08-02T19:38:42.4444834Z [36;1mexport BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')[0m
2021-08-02T19:38:42.4445782Z [36;1mecho "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV[0m
2021-08-02T19:38:42.4489050Z shell: /usr/bin/bash -e {0}
2021-08-02T19:38:42.4690016Z ##[error]Unable to process file command 'env' successfully.
2021-08-02T19:38:42.4703378Z ##[error]Invalid environment variable format 'Indicate that a variable can have the value `null`. Null-Safety is default from version **2.12.0** in the Dart language.'
2021-08-02T19:38:42.4890985Z Post job cleanup.
...

Answer №1

If you're looking for an alternative approach, check out the instructions in the documentation for Github Actions available at: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings

Instead of the standard method shown below:

  export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
  echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV

You can employ the multiline string formatting as outlined in the documentation using:

{name}<<{delimiter}
{value}
{delimiter}
  export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
  echo "BUILD_VERSION<<EOFMARKER" >> ${GITHUB_ENV}
  echo "${BUILD_VERSION}" >> ${GITHUB_ENV}
  echo "EOFMARKER" >> ${GITHUB_ENV}

Note: it's essential to heed the cautionary advice regarding security risks associated with utilizing a constant like EOF as a delimiter here: https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections. Therefore, when dealing with input that may be considered "user-generated," opt for a random data generator as your delimiter, such as:

  export BUILD_VERSION=$(grep version package.json | awk -F \" '{print $4}')
  delimiter="$(openssl rand -hex 8)"
  echo "BUILD_VERSION<<${delimiter}" >> ${GITHUB_ENV}
  echo "${BUILD_VERSION}" >> ${GITHUB_ENV}
  echo "${delimiter}" >> ${GITHUB_ENV}

Answer №2

The issue at hand is not related to the content of your README.md. Instead, the problem lies in the presence of certain strings containing the word version within your package.json file. These lines are being added to your $GITHUB_ENV file, and all but the first one are causing syntax errors.

BUILD_VERSION=3.2.8
Indicate that a variable can have the value `null`. Null-Safety is default from version **2.12.0** in the Dart language.
Disable ask for confirmation to start the conversion from the file `models.jsonc`.
Default target directory when conversion is from the file `models.jsonc`.

You may want to consider using a more precise regular expression, or as suggested in a previous comment, utilize Awk for filtering which offers greater accuracy. This approach will help eliminate the unnecessary use of grep.

      - name: extract version number
        run: |
          BUILD_VERSION=$(awk -F \" '$2 == "version" {print $4}' package.json)
          echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV

You could simplify this process into a single line; it appears that employing an extra temporary variable was not aiding in debugging (though adding set -x to the shell script snippet might have been helpful).

      - name: extract version number
        run:
          awk -F \" '$2 == "version" {print "BUILD_VERSION=" $4}' package.json >> $GITHUB_ENV

For best practice, it's recommended to use a JSON-specific tool like jq to extract only the version number and avoid extracting any extraneous data.

      - name: extract version number
        run:
          jq -r '"BUILD_VERSION=\(.version)"' package.json >> $GITHUB_ENV

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using the parent id in knockoutJs to create a nested menu

I'm currently attempting to create a nested menu using the JSON data provided by the client. Here is the data: var serverData = [ { Id: "menuColorSearch", Text: "Color search" }, { Id: "menuAncillaryProductM ...

The Next.js build encountered an error - unable to locate function in next/script module

While constructing a CMS using next.js, one of the key components is media management through Cloudinary. The integration of the Cloudinary Media Library widget was successful during development using next/script. However, an error has now emerged that pre ...

Learn how to mock asynchronous calls in JavaScript unit testing using Jest

I recently transitioned from Java to TypeScript and am trying to find the equivalent of java junit(Mockito) in TypeScript. In junit, we can define the behavior of dependencies and return responses based on test case demands. Is there a similar way to do t ...

Creating an Http interceptor in Ionic 3 and Angular 4 to display a loading indicator for every API request

One of my current challenges involves creating a custom HTTP interceptor to manage loading and other additional functions efficiently. Manually handling loading for each request has led to a considerable increase in code. The issue at hand: The loader is ...

Storing freshly acquired JSON data via AJAX into an already existing array

I am currently converting the dynamic data being displayed into JSON, then using AJAX to send it to a specific URL. Subsequently, I retrieve the saved JSON data through AJAX and update my display accordingly. However, an error is occurring stating that &a ...

Listview of Flutter Json Map containing key-value pairs with string keys and double values

I am facing an issue where I am unable to display JSON data on a ListView using listview.builder. While I can successfully retrieve the values from the JSON, displaying them on the listview seems to be a challenge. Here is the JSON data: {"success":true, ...

What steps can be taken to troubleshoot a TypeScript-powered Node.js application running in WebStorm?

Seeking advice on debugging a node.js application utilizing TypeScript within WebStorm - any tips? ...

What method can be used to determine a number that is nonzero?

Defining the type of Result has presented some challenges for me. It should adhere to one of the following patterns: type Result<Some> = { code: 0; some_result: ...} // or type Result = { code: NonZero; message: string} How can I properly type this? ...

Getting information from a MySQL database and transferring it to an Android device

I'm attempting to retrieve user details from MySQL to my Android application. I am posting data from Android and obtaining the values using $_POST['mobile'] and $_POST['usertype'] in my PHP page. To verify if the data is being post ...

Find the value of a JavaScript string variable using an alternative name

My latest JavaScript function is designed to fetch JSON data from either a server or local files on any browser. This piece of code processes JSON from two sources: an XMLHttpRequest response, or a variable imported via script. In the case of the latter, ...

A guide on converting your current Angular app into a "fully strict" application – follow these steps!

I started developing an Angular Application back in Angular 4 and now it has been upgraded to Angular 12. However, during the initial development phase, the strict mode was not enabled. Now that the application is stable and live in production, I am lookin ...

Transform any JSON data into a CSV file by utilizing a custom template or schema language

Looking to streamline an ETL pipeline by converting JSON strings into tabular CSV format. The JSON object can vary in structure, so flexibility is key - users should be able to customize the conversion process via a configuration or template. For example: ...

What is the best way to verify the type of an object received from request.body in Typescript

Is it possible to check the object type from the request body and then execute the appropriate function based on this type? I have attempted to do so in the following manner: export interface SomeBodyType { id: string, name: string, [etc....] } ...

Develop an innovative Android application that interfaces with an ASP.NET WebAPI server to efficiently exchange intricate data structures

Currently, I have an Android App that is connected to my ASP.NET WebApi Server through Web Services. To send requests, I am utilizing AsyncHttpClient and for passing parameters, I am using RequestParams. However, I am facing an issue when trying to send a ...

Displaying the contents of an ArrayList in a Spring Boot application

After creating an ArrayList with the JSON values from a Rest API, I encountered the following code to read the Rest API: @RestController public class exemploclass { @RequestMapping(value="/vectors") ...

Having difficulty in executing the node app.js script

I am currently learning node.js and encountering an issue when trying to run the app.js file using the command node app.js. The terminal shows no output, neither errors nor any other information. Here is the sequence of steps I have followed: $ brew insta ...

Looking to transform a list into JSON format using JavaScript?

I have a collection that looks like this: <ol class="BasketballPlayers"> <li id="1">Player: LeBron, TotalPoints: 28753, MVP: true</li> <li id="2">Player: Steph, TotalPoints: 17670, MVP: true< ...

Transmitting JSON AJAX response to populate location markers on Google Maps

When a button is clicked, an AJAX response is triggered to display JSON data based on a search query. My goal is to take the all_locations variable from the AJAX response and use it to show markers on a Google map. I'm uncertain about how to achieve t ...

Is it better to process data in a React app using Express or handle it directly on the front end with React?

Hey there, I need some advice on how to create a league table for my application. The JSON data structure is set up like this: I'm considering whether to calculate each player's league data on the front-end using React by looping through the fixt ...

How to troubleshoot Python errors (+mod_wsgi) using the Chrome Network panel

As a newcomer to Python, I am facing an issue with viewing error messages. The problem arises when a javascript function is making a call as follows: $.getJSON('test.py', {data: 'somedata'}, function(return){alert(return.echo)}) In th ...