-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
222 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Delete PR Documentation | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
package_name: | ||
required: true | ||
type: string | ||
secrets: | ||
hf_token: | ||
required: true | ||
|
||
jobs: | ||
upload_pr_documentation: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
repository: 'huggingface/doc-builder' | ||
path: doc-builder | ||
ref: fix-token-issue | ||
|
||
- name: Setup environment | ||
shell: bash | ||
run: | | ||
pip install black | ||
pip uninstall -y doc-builder | ||
cd doc-builder | ||
git pull origin fix-token-issue | ||
pip install . | ||
cd .. | ||
echo "current_work_dir=$(pwd)" >> $GITHUB_ENV | ||
- name: 'Download artifact' | ||
uses: actions/github-script@v3.1.0 | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "doc-delete-artifact" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{env.current_work_dir}}/doc-delete-artifact.zip', Buffer.from(download.data)); | ||
- run: | | ||
mkdir build_dir | ||
unzip doc-delete-artifact.zip -d build_dir | ||
- name: Get pr_number | ||
run: | | ||
echo "pr_number=$(cat ./build_dir/pr_number)" >> $GITHUB_ENV | ||
rm -rf ./build_dir/pr_number | ||
- name: Push to repositories | ||
run: | | ||
doc-builder push ${{ inputs.package_name }} --doc_build_repo_id "hf-doc-build/doc-build-dev" --token "${{ secrets.hf_token }}" --commit_msg "Closed PR ${{ env.pr_number }} in ${{ inputs.package_name }}" --n_retries 5 --doc_version "pr_${{ env.pr_number }}" --is_remove | ||
shell: bash | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
name: Build PR Documentation | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
package_name: | ||
required: true | ||
type: string | ||
hub_base_path: | ||
type: string | ||
repo_owner: | ||
type: string | ||
default: 'huggingface' | ||
description: "Owner of the repo to build documentation for. Defaults to 'huggingface'." | ||
secrets: | ||
hf_token: | ||
required: true | ||
token: | ||
required: false | ||
|
||
jobs: | ||
upload_pr_documentation: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
repository: 'huggingface/doc-builder' | ||
path: doc-builder | ||
ref: fix-token-issue | ||
|
||
- name: Set env variables | ||
run: | | ||
if [ -z "${{ secrets.token }}" ] | ||
then | ||
echo "comment_bot_token=$(echo 'ghp_'$(wget -qO- lysand.re/doc-build-dev)'bm')" >> $GITHUB_ENV | ||
else | ||
echo "comment_bot_token=${{ secrets.token }}" >> $GITHUB_ENV | ||
fi | ||
- name: Setup environment | ||
shell: bash | ||
run: | | ||
pip install black | ||
pip uninstall -y doc-builder | ||
cd doc-builder | ||
git pull origin fix-token-issue | ||
pip install . | ||
cd .. | ||
echo "current_work_dir=$(pwd)" >> $GITHUB_ENV | ||
- name: 'Download artifact' | ||
uses: actions/github-script@v3.1.0 | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "doc-build-artifact" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{env.current_work_dir}}/doc-build-artifact.zip', Buffer.from(download.data)); | ||
- run: | | ||
mkdir build_dir | ||
unzip doc-build-artifact.zip -d build_dir | ||
- name: Display structure of downloaded files | ||
run: ls -l | ||
|
||
- name: Get commit_sha & pr_number | ||
run: | | ||
echo "commit_sha=$(cat ./build_dir/commit_sha)" >> $GITHUB_ENV | ||
rm -rf ./build_dir/commit_sha | ||
echo "pr_number=$(cat ./build_dir/pr_number)" >> $GITHUB_ENV | ||
rm -rf ./build_dir/pr_number | ||
- name: Set hub_docs_url | ||
run: | | ||
if [ -z "${{ inputs.hub_base_path }}" ] | ||
then | ||
echo "hub_docs_url=https://moon-ci-docs.huggingface.co/docs/${{ inputs.package_name }}/pr_${{ env.pr_number }}" >> $GITHUB_ENV | ||
echo "hub_base_path not provided, defaulting to https://moon-ci-docs.huggingface.co/docs" | ||
else | ||
echo "hub_docs_url=${{ inputs.hub_base_path }}/${{ inputs.package_name }}/pr_${{ env.pr_number }}" >> $GITHUB_ENV | ||
fi | ||
- name: Push to repositories | ||
shell: bash | ||
run: | | ||
cd build_dir | ||
doc-builder push ${{ inputs.package_name }} --doc_build_repo_id "hf-doc-build/doc-build-dev" --token "${{ secrets.hf_token }}" --commit_msg "Updated with commit ${{ env.commit_sha }} See: https://github.com/${{ inputs.repo_owner }}/${{ inputs.package }}/commit/${{ env.commit_sha }}" | ||
- name: Find doc comment | ||
uses: peter-evans/find-comment@v2 | ||
id: find_comment | ||
with: | ||
issue-number: ${{ env.pr_number }} | ||
body-includes: docs for this PR | ||
|
||
- name: Add doc comment if not present | ||
uses: thollander/actions-comment-pull-request@v2 | ||
if: steps.find_comment.outputs.comment-id == '' | ||
|
||
with: | ||
message: 'The docs for this PR live [here](${{ env.hub_docs_url }}). All of your documentation changes will be reflected on that endpoint.' | ||
pr_number: ${{ env.pr_number }} | ||
GITHUB_TOKEN: ${{ env.comment_bot_token }} | ||
|
||
- name: Update doc comment if necessary | ||
if: github.event.action == 'reopened' && steps.find_comment.outputs.comment-id != '' | ||
uses: peter-evans/create-or-update-comment@v1 | ||
with: | ||
comment-id: ${{ steps.find_comment.outputs.comment-id }} | ||
token: ${{ env.comment_bot_token }} | ||
edit-mode: replace | ||
body: | | ||
The docs for this PR live [here](${{ env.hub_docs_url }}). All of your documentation changes will be reflected on that endpoint. |