Installation failed on macOS #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lookatme Preview | |
on: | |
issue_comment: | |
types: | |
- created | |
jobs: | |
generate_preview: | |
continue-on-error: true | |
runs-on: ubuntu-latest | |
if: (github.event.issue && contains(github.event.issue.milestone.title, 'v3.0')) && contains(github.event.comment.body, 'gif=true') | |
services: | |
selenium: | |
image: selenium/standalone-chrome | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Maybe Checkout 3.0-dev | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
async function checkout30dev() { | |
await exec.exec("git", ["fetch", "origin", "3.0-dev:3.0-dev"]); | |
await exec.exec("git", ["checkout", "3.0-dev"]); | |
} | |
if (context.payload.issue.pull_request) { | |
let response = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
}); | |
core.info(`response: ${JSON.stringify(response)}`); | |
const pr = response.data; | |
if (pr.base.ref != "3.0-dev") { | |
core.info("In a PR, but not merging into 3.0-dev, will directly use 3.0-dev for the preview"); | |
await checkout30dev(); | |
} else { | |
core.info(`In a PR that is merging into 3.0-dev, using PR context for the preview: ${pr.head.ref} (${pr.head.sha})`); | |
await exec.exec("git", [ | |
"fetch", "origin", `${pr.head.sha}:${pr.head.ref}`, | |
]); | |
await exec.exec("git", ["checkout", pr.head.ref]); | |
} | |
} else { | |
core.info("Not in a PR, using 3.0-dev directly"); | |
await checkout30dev(); | |
} | |
- name: Setup Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install Python dependencies | |
run: | | |
pip install .[dev] | |
- name: Generate preview | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require("fs/promises"); | |
const comment = context.payload.comment; | |
core.info("Writing comment info to disk"); | |
await fs.writeFile("input.md", comment.body); | |
core.info("Generating gif from extracted comment body"); | |
await exec.exec("bin/md_gif_extractor.py", ["-i", "input.md", "-o", "preview.gif"]); | |
core.info("Uploading preview to imgur"); | |
let curlOutput = ""; | |
const options = { | |
listeners: { | |
stdout: (data) => { | |
curlOutput += data.toString(); | |
} | |
} | |
}; | |
// was using axios and directly uploading, ran into errors, used curl | |
// to help debug, got it working, don't feel like reverting axios | |
// now. "it works" - shrug | |
await exec.exec("curl", [ | |
"--location", | |
"--request", "POST", | |
"https://api.imgur.com/3/image", | |
"--header", "Authorization: Client-ID ${{ secrets.IMGUR_CLIENT_ID }}", | |
"--form", "image=@preview.gif", | |
"--form", "type=file", | |
], options); | |
core.info(`Got curl response:\n${curlOutput}\n`); | |
let resp = JSON.parse(curlOutput); | |
if (!resp.data) { | |
core.info(`Error uploading to imgur: ${curlOutput}`); | |
} else { | |
core.info("Commenting on issue"); | |
const imgurUrl = resp.data.link; | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: `The preview below was generated by the markdown in [this comment](${context.payload.comment.html_url}):\n\n![markdown preview image](${imgurUrl})`, | |
}); | |
} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
path: preview.gif |