Coder Social home page Coder Social logo

create-json's Introduction

Create a .json file dynamically on your workflow


Example of the output on the .json file created:

{
    "name":"jsdaniell",
    "password":"mypass"
}

How to use

You can define a json structure on the secrets of your repository:

{
    "name":"jsdaniell",
    "password":"mypass"
}

MY_JSON (Secrets variables can be configured on repository settings > Secrets)

and use in this way:

    - name: create-json
      id: create-json
      uses: jsdaniell/[email protected]
      with:
        name: "credentials.json"
        json: ${{ secrets.MY_JSON }}

Or just declare a string of a json on the property json like:

    - name: create-json
      id: create-json
      uses: jsdaniell/[email protected]
      with:
        name: "new-json-file.json"
        json: '{"name":"jsdaniell", "password":"mypass"}'

The json have to be inside a string.

You also can save the json on a subdirectory using the property dir:

    - name: create-json
      id: create-json
      uses: jsdaniell/[email protected]
      with:
        name: "credentials.json"
        json: ${{ secrets.CREDENTIALS_JSON }}
        dir: 'src/'

Remember that when you create a .json file, the file was not commited, you have to commit the file if you will use the HEAD branch with the file to push the repository to other service, like deploy to heroku or other platforms.

If you want to create more than one json files, you have to specify different IDs for the action like:

    - name: create-json
      id: create-json-1 # First ID
      uses: jsdaniell/[email protected]
      with:
        name: "credentials.json"
        json: ${{ secrets.CREDENTIALS_JSON }}
        dir: 'src/'
    - name: create-json
      id: create-json-2  # Second ID
      uses: jsdaniell/[email protected]
      with:
        name: "other.json"
        json: '{"name":"jsdaniell", "password":"mypass"}'
        dir: 'src/'

Real Example (Creating and Using on Other Steps)

name: Heroku CI - CD

on:
  push:
    branches: [ master ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-go@v1
        with:
          go-version: '1.14.6'
      - run: cd src && go mod vendor
      - name: create-json
        id: create-json
        uses: jsdaniell/[email protected]
        with:
          name: "devdatatools-firebase-adminsdk.json"
          json: ${{ secrets.CREDENTIALS_JSON }}
          dir: "src/"
      - run: git config --global user.email "[email protected]" && git config --global user.name "jsdaniell" && git add . && git add --force src/devdatatools-firebase-adminsdk.json && git status && git commit -a -m "Deploy Heroku Commit with the Credentials JSON created!"
      - uses: akhileshns/[email protected]
        with:
          heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
          heroku_app_name: "dev-data-tools-api-golang"
          heroku_email: "[email protected]"
          appdir: "src"

After commit and use with Heroku the file is deleted after the workflow and the JSON is not showed on the log, perfect for public repositories.

Contribute

You can submit an issue or PR anytime for the improvement this action!

Version v1.2.3 (Node 20)

create-json's People

Contributors

github-actions[bot] avatar jmtellez avatar jsdaniell avatar mariusvb avatar murillocunha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

create-json's Issues

Update set-output use

I get the warning Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Node.js 16 actions are deprecated

Hi, it seems this package is using node 16 which is now deprecated. I guess the runs block needs to be updated.

Please update the following actions to use Node.js 20: jsdaniell/[email protected]. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

Argument list too long - On big JSON array

I an try to create a file based on response of a previous step, and when i try to create a file using this lib, generates this error:

Error: An error occurred trying to start process '/home/runner/runners/2.301.1/externals/node16/bin/node' with working directory '/home/runner/work/landing-page-processor/landing-page-processor'. Argument list too long

See my file in:
https://firebasestorage.googleapis.com/v0/b/sortegram.appspot.com/o/artifact.json?alt=media&token=ab33d5f4-ce6d-456b-af62-e05043e4a777

JSON Not created correctly

I tried creating a simple JSON file with the following content:

{
  "auth": {
    "user": "",
    "password": ""
  }
}

To do this I created a repository variable containing the above JSON and then tried to call it in my deploy job. This is for a .NET application and looks as follows:

      - name: Create App Settings
        id: create-json
        uses: jsdaniell/[email protected]
        with:
          name: 'appsettings.json'
          json: ${{ vars.APP_SETTINGS }}

What I see being created though is a file that looks like this:

auth:
 user:
 password:

What's causing this formatting issue?

"set-output" is getting deprecated

I think that this action is the culprit of some recent warnings I'm getting in my action logs. More specifically this error:

The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

You can read about how to change it here.

Only the compiled code is available in your repo, but if you share the Typescript I can help change it if needed.

command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.