DEV Community

Yevhen Fabizhevskyi
Yevhen Fabizhevskyi

Posted on

Introducing JSONBin GitHub Action

Hi guys, I would like to introduce one of the GitHub Actions that I have implemented during GitHub Actions Hackathon. BTW, I've received today an email that I have qualified for a GitHub Hackathon prize, so just sent them my post address and will see what I get :)

Briefly about what all these words in a title mean (if you don't know yet):

  • GitHub Actions is really powerful tool that can be used as a CI/CD (but not limited to, actually you can do anything you want with it) and if you're still not aware of it I recommend you to know more here, and here, and here.
  • JSONBin is a service where you can store your own bins. Bin means actually URL that returns anything you want. For example, I need some URL that will return {"greetings":"Hello dev.to!"}, so I can sign up to JSONBin and create a bin with this response. It will generate URL for me that might look like this - https://api.jsonbin.io/b/5e8d473dab2e011ba969a6db and I can use it for any purpose I need and even share with someone (if I make it public). It can be used to test something in your app or even to store some data there, e.g. work experience or skills that can be used in your portfolio application. Also, JSONBin works with collections, GeoIP, Schema docs, etc. You can find full API Docs here.

The main idea of this action is to have URL that will return any response you want in JSON format. You can store job information in your bins for future usage or even use this URL in your CI pipeline.

How to configure

So, let's start from the beginning and configure this action in your repository.

Prerequisites

  1. Repository in GitHub
  2. Account in JSONBin.io

Configuration

  1. Go to API Keys page at JSONBin.io and create a new key.
  2. Go to your repository in GitHub and create a new secret with the name API_KEY. Here you can find an information on how to create a secret in your GitHub repository.
  3. Go to the root of your repo and create jsonbin.yml in .github/workflows folder with the following content:
name: JSONbin

on: push

jobs:
  jsonbin:
    name: Test JSONbin
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: fabasoad/jsonbin-action@v1.0.1
        id: jsonbin
        with:
          body: '{"workflow": "${{ github.workflow }}", "author": "${{ github.actor }}", "number": "${{ github.run_number }}"}'
          method: 'CREATE'
          api_key: ${{ secrets.API_KEY }}
      - name: Check bin_id
        run: |
          echo "Bin ID = ${{ steps.jsonbin.outputs.bin_id }}"
          echo "URL = ${{ steps.jsonbin.outputs.url }}"
Enter fullscreen mode Exit fullscreen mode

Now push your changes, go to Actions tab of GitHub repository and wait till job is finished. Take a look at job output to find the generated result:

Here is the result of generated link call:

So it returns exactly what we expect. In this example I use CREATE method but you can also UPDATE and DELETE created bin if needed. All documentation you can find in README of the repository.

Link

JSONBin GitHub Action

Please feel free to create any issue (either bug report or feature request), pull request or just leave a comment with the proposition. I would love to hear any feedback. Also, don't forget to star this action ;) Thank you.

Top comments (0)