Home > Enterprise >  How to Set Gihub Secret with a Binary File for Github Workflow?
How to Set Gihub Secret with a Binary File for Github Workflow?

Time:01-21

I would like to add one of my API configuration file (binary.file) to the Github secret (MY_BINARY_SECRET). Then it will be read and wrote to binary.file again in the workflow:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install System
        run: |
          sudo apt-get update
          sudo apt-get install -y pip python3.8-venv libcurl4-openssl-dev

      - name: Set up configurations
        shell: bash
        run: |
          echo "${{ secrets.MY_BINARY_SECRET }}" > binary.file
          python3 .... # the python script will need binary.file to complete authentication  

However, I tried many hours with different ways to copy the binary content to the Github Secret, but all failed. I tried pbcopy, less, cat. Does anyone know how to write a binary file via Github Secret in the github actions? Or a better solution?

Thank you!

CodePudding user response:

(Extending my comment):

Use base64 to encode binary string to text and decode it back to binary. This is pretty standard trick.

First, encode at home:

echo "$MY_BINARY_SECRET" | base64 --wrap=0 > secret.b64

--wrap=0 to make the output text one long line; useful for echo below.

Upload text file secret.b64 as the secret to GitHub. Decode it using

echo -n "${{ secrets.MY_BINARY_SECRET }}" | base64 --decode > binary.file

Advice: first try decoding locally and compare with the original string. Must be the same.

  •  Tags:  
  • Related