octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API

Home Page:https://github.com/marketplace/actions/GitHub-API-Request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help with POST /markdown

altso opened this issue · comments

I'm trying to convert readme.md to readme.html using POST /markdown endpoint but could not figure out how to pass multi-line text parameter to the endpoint. The last line in the snippet below seems to be problematic, as it seems like lines that start with # (markdown headings) are being skipped:

    - name: Read README.md
      id: read_readme
      run: |
        README=$(cat README.md)
        README="${README//'%'/'%25'}"
        README="${README//$'\n'/'%0A'}"
        README="${README//$'\r'/'%0D'}"
        echo ::set-output name=readme::$README
        echo $README
    - name: Print README.md
      run: |
        echo "${{ steps.read_readme.outputs.readme }}"
    - name: Compile README.md
      id: compile_readme
      uses: octokit/request-action@v2.x
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        route: POST /markdown
        text: |+
          ${{ steps.read_readme.outputs.readme }}

Any suggestions on how to "fix" that behavior?

Is there a way to make request-action to read parameters directly from the file bypassing all the escape/unescape string hassle?

Here is an example:

readme.md:

# Header 1

## Header 2

1. Step 1
2. ...
3. Profit!

readme.html with missing headers and new lines:

<ol>
<li>Step 1 2. ... 3. Profit!</li>
</ol>

Did you try to do just

        text: ${{ steps.read_readme.outputs.readme }}

What error are you seeing?

I did, it passes null as text. I assume it's because the first character in readme.txt is #

I'm no yaml expert, but can you try escaping with |-? I haven't seen |+ before

      with:
        route: POST /markdown
        text: |-
          ${{ steps.read_readme.outputs.readme }}

Ok, I figured it out. You need to convert multi-line to a single line with \ns.

    - name: Read README.md
      id: read_readme
      run: |
        README=$(cat README.md)
        README="${README//$'\n'/'\n'}"
        README="${README//$'\r'/''}"
        README="${README//$'\"'/'\"'}"
        echo ::set-output name=readme::"$README"
        echo $README
    - name: Compile README.md
      id: compile_readme
      uses: octokit/request-action@v2.x
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        route: POST /markdown
        text: |
          "${{ steps.read_readme.outputs.readme }}"
    - name: Produce README.html
      shell: pwsh
      run: |
        $env:README | ConvertFrom-Json > README.html
        type README.html

README.md:

# Header 1

## Header 2

1. Step 1
2. ...
3. Profit!



"The quick brown fox jumps over the lazy dog"

README.html

<h1>
<a id="user-content-header-1" class="anchor" href="#header-1" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Header 1</h1>
<h2>
<a id="user-content-header-2" class="anchor" href="#header-2" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Header 2</h2>
<ol>
<li>Step 1</li>
<li>...</li>
<li>Profit!</li>
</ol>
<p>"The quick brown fox jumps over the lazy dog"</p>