Skip to content

[技术分享]套娃之arm架构下的MacBook通过parallels+rosetta安装Linux amd64版本的IDA Pro #59

[技术分享]套娃之arm架构下的MacBook通过parallels+rosetta安装Linux amd64版本的IDA Pro

[技术分享]套娃之arm架构下的MacBook通过parallels+rosetta安装Linux amd64版本的IDA Pro #59

Workflow file for this run

name: issue-to-post
on:
issues:
types: [opened, edited]
jobs:
sync-issue-to-blog:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Generate Abstract
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_TOKEN }}
run: |
ISSUE_ID=${{ github.event.issue.number }}
issue_data=$(gh api /repos/${{ github.repository }}/issues/${ISSUE_ID})
BLOG_CONTENT=$(echo "$issue_data" | jq -r '.body')
BLOG_TITLE=$(echo "$issue_data" | jq -r '.title')
CONTENT=$(echo "$issue_data" | jq -r '.body' | sed 's/ [ [:punct:]]//g' | tr -d '\n' | tr -d '\r' | head -c 2800 )
REQUEST='{
"model": "text-davinci-003",
"prompt": "下面是一个markdown文档,请生成不超过300字的摘要和5个关键词,用json格式输出,如:{\"abstract\":\"the abstract\", \"keywords\":[\"keyword1\",\"keywordd2\"] }请再输出结果前插入--OPENAI-RESULT-START--。\n\n",
"temperature": 0.618,
"max_tokens": 500,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}'
REQUEST=$(echo "$REQUEST" | jq --ascii-output --arg CONTENT "$CONTENT" --arg TITLE "$BLOG_TITLE" '.prompt = .prompt + "标题:"+ $TITLE + $CONTENT')
RESPONSE=$(curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d "${REQUEST}")
ANSWER=$(echo $RESPONSE | jq -r ".choices[0].text" | sed -n '/--OPENAI-RESULT-START--/,$p' | sed '1d')
BLOG_DESCRIPTION=$(echo $ANSWER | jq -r ".abstract")
echo BLOG_DESCRIPTION:$BLOG_DESCRIPTION
BLOG_TAGS=$(echo $BLOG_TAGS $(echo $ANSWER | jq -r '.keywords') | jq -j -s "add")
echo BLOG_TAGS:$BLOG_TAGS
export BLOG_DESCRIPTION BLOG_TAGS
- name: Create Blog Post
id: create_post
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ${{ github.event.issue.author_association }} != 'COLLABORATOR'; then
echo "not COLLABORATOR,exit"
exit
fi
ISSUE_ID=${{ github.event.issue.number }}
GITHUB_REPO="${{ github.repository }}"
issue_data=$(gh api /repos/${{ github.repository }}/issues/${ISSUE_ID})
ISSUE_TITLE=$(echo "${{ github.event.issue.title }}" | sed 's/[[:space:]]/-/g')
ISSUE_DATE=$(echo "${{ github.event.issue.created_at }}" | cut -c1-10 | sed 's/-//g')
POST_PATH="content/posts/${ISSUE_DATE}-${ISSUE_TITLE}.md"
for file in content/posts/*.md; do
yaml=$(sed -n '/---/,/---/p' "${file}")
if echo "${yaml}" | grep -q "issueId: ${ISSUE_ID}"; then
OLD_POST_PATH="${file}"
if [ "$OLD_POST_PATH" != "$POST_PATH" ]; then
mv "$OLD_POST_PATH" "$POST_PATH"
fi
break
fi
done
BLOG_TITLE=$(echo "$issue_data" | jq -r '.title')
BLOG_DATE=$(echo "$issue_data" | jq -r '.created_at')
BLOG_DESCRIPTION=${BLOG_DESCRIPTION:-""}
# BLOG_DESCRIPTION=""
TEMP_TAGS=$(echo "$issue_data" | jq -r '[.labels[].name]')
BLOG_TAGS=${BLOG_TAGS:-"$TEMP_TAGS"}
BLOG_CONTENT=$(echo "$issue_data" | jq -r '.body')
export GITHUB_REPO ISSUE_ID POST_PATH BLOG_TITLE BLOG_DATE BLOG_DESCRIPTION BLOG_TAGS BLOG_CONTENT
envsubst < template/template.md > ${POST_PATH}
- name: Commit and Push Changes
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add .
git commit -m "Sync issue #${{ github.event.issue.number }} to blog"
git push origin blog
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}