Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Aug 29, 2023
2 parents 0483229 + f5e22f8 commit d754856
Show file tree
Hide file tree
Showing 19 changed files with 774 additions and 53 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build-docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build Docs
inputs:
extra-config:
required: false
type: string
target-folder:
require: false
type: string

runs:
using: composite
steps:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7

- name: Configure
shell: bash
env:
TARGET_FOLDER: ${{ inputs.target-folder }}
EXTRA_CONFIG: ${{ inputs.extra-config }}
run: |
[[ ${RUNNER_DEBUG:-0} -eq 1 ]] && set -x
REPO_NAME=$(jq -r ".repository.name" "$GITHUB_EVENT_PATH")
TEMP_CONFIG=$(mktemp)
# avoid look up of API as it doesn't work from within actions without exposing the GITHUB_TOKEN here which is a security risk
cat <<EOF >> ${TEMP_CONFIG}
repository_nwo: ${GITHUB_REPOSITORY}
EOF
if [[ -n "${TARGET_FOLDER}" ]]
then
echo "baseurl: /${REPO_NAME}/${TARGET_FOLDER}" >> ${TEMP_CONFIG}
fi
# allow override of everything
cat <<EOF >> ${TEMP_CONFIG}
${EXTRA_CONFIG}
EOF
echo "Adding additional config settings:"
cat ${TEMP_CONFIG} | tee -a docs/_config.yml
- name: Install and Build
shell: bash
env:
BUNDLE_GEMFILE: ./docs/Gemfile
run: |
# TODO find a way for jekyll to perform this automatically
convert docs/_assets/images/logo.png -define icon:auto-resize=256,64,48,32,16 docs/favicon.ico
bundle install
bundle exec jekyll build --source docs/ --destination build
39 changes: 39 additions & 0 deletions .github/workflows/build-documentation-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build Docs Preview
on:
pull_request:
types:
- closed
- opened
- reopened
- synchronize
paths:
- 'docs/**'
- '.github/workflows/build-documentation-preview.yml'
- '.github/workflows/build-docs/**'

jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Build docs 🔧
if: github.event.action != 'closed'
uses: ./.github/workflows/build-docs
with:
target-folder: "pr-preview/pr-${{ github.event.number }}"
extra-config: |
plugin_script_base_path: "/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }}"
- uses: actions/upload-artifact@v2
if: github.event.action != 'closed'
with:
name: jekyll-docs
path: |
build/**
- uses: actions/upload-artifact@v2
with:
name: source-event
path: ${{ github.event_path }}
84 changes: 84 additions & 0 deletions .github/workflows/build-gem-package-notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: add gem artifact links
on:
workflow_run:
workflows: ['publish-gem']
types:
- completed

jobs:
artifacts-url-comments:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
name: Add artifact links to pull request
runs-on: ubuntu-22.04
steps:
- name: 'Download artifact'
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
},
);
if (!artifacts.length) {
return core.error(`No artifacts found`);
}
var matchArtifact = artifacts.find((artifact) => {
return artifact.name == "pr"
});
if (matchArtifact === undefined) {
return core.error(`No PR artifact found`);
}
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- uses: actions/github-script@v6
with:
# This snippet is public-domain, taken from
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
script: |
async function upsertComment(owner, repo, issue_number, purpose, body) {
const {data: comments} = await github.rest.issues.listComments(
{owner, repo, issue_number});
const marker = `<!-- bot: ${purpose} -->`;
body = marker + "\n" + body;
const existing = comments.filter((c) => c.body.includes(marker));
if (existing.length > 0) {
const last = existing[existing.length - 1];
core.info(`Updating comment ${last.id}`);
await github.rest.issues.updateComment({
owner, repo,
body,
comment_id: last.id,
});
} else {
core.info(`Creating a comment in issue / PR #${issue_number}`);
await github.rest.issues.createComment({issue_number, body, owner, repo});
}
}
const {owner, repo} = context.repo;
const run_id = ${{github.event.workflow_run.id}};
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
if (!artifacts.length) {
return core.error(`No artifacts found`);
}
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./NR'));
let body = `Download the latest artifacts for this pull request here:\n`;
for (const art of artifacts) {
if (art.name == 'pr') {
continue;
}
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
}
core.info("Review thread message body:", body);
await upsertComment(owner, repo, issue_number, "nightly-link", body);
116 changes: 116 additions & 0 deletions .github/workflows/deploy-docs-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Deploy Docs Preview
on:
workflow_run:
workflows:
- "Build Docs Preview"
types:
- completed

permissions:
contents: write
pull-requests: write

jobs:
deploy-preview:
concurrency: publish-gh-pages
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: 'Download artifact'
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{github.event.workflow_run.id }}

- name: Configure Settings
env:
SOURCE_EVENT_PATH: source-event/event.json
run: |
echo "Using ${SOURCE_EVENT_PATH} as event source"
event_type=$(jq -r ".action" "$SOURCE_EVENT_PATH")
echo "event_type is $event_type"
case $event_type in
"opened" | "reopened" | "synchronize")
echo "action=deploy" >> $GITHUB_ENV
;;
"closed")
echo "action=remove" >> $GITHUB_ENV
;;
*)
echo "unknown event type $event_type; no action to take"
echo "action=none" >> $GITHUB_ENV
;;
esac
org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2)
if [ ! -z "$customurl" ]; then
pagesurl="$customurl"
elif [ "${org}.github.io" == "$thirdleveldomain" ]; then
pagesurl="${org}.github.io"
else
pagesurl=$(echo "$GITHUB_REPOSITORY" | sed 's/\//.github.io\//')
fi
echo "pagesurl=$pagesurl" >> $GITHUB_ENV
echo "preview_branch=gh-pages" >> $GITHUB_ENV
pr=$(jq -r ".number" "$SOURCE_EVENT_PATH")
echo "pr=${pr}" >> $GITHUB_ENV
echo "targetdir=pr-preview/pr-${pr}" >> $GITHUB_ENV
echo "emptydir=$(mktemp -d)" >> $GITHUB_ENV
echo "datetime=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
- name: Deploy preview directory
if: env.action == 'deploy'
uses: JamesIves/[email protected]
with:
branch: ${{ env.preview_branch }}
folder: jekyll-docs
target-folder: ${{ env.targetdir }}
commit-message: Deploy preview for PR ${{ env.pr }} 🛫
force: false

- name: Leave a comment after deployment
if: env.action == 'deploy' && env.deployment_status == 'success'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ env.pr }}
header: pr-preview
message: "\
:rocket: Deployed preview to
https://${{ env.pagesurl }}/${{ env.targetdir }}/
on branch [`${{ env.preview_branch }}`](\
${{ github.server_url }}/${{ github.repository }}\
/tree/${{ env.preview_branch }})
at ${{ env.datetime }}
"

- name: Remove preview directory
if: env.action == 'remove'
uses: JamesIves/[email protected]
with:
branch: ${{ env.preview_branch }}
folder: ${{ env.emptydir }}
target-folder: ${{ env.targetdir }}
commit-message: Remove preview for PR ${{ env.pr }} 🛬
force: false

- name: Leave a comment after removal
if: env.action == 'remove' && env.deployment_status == 'success'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ env.pr }}
header: pr-preview
message: "\
Preview removed because the pull request was closed.
${{ env.datetime }}
"
39 changes: 39 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy Docs
on:
workflow_call:
inputs:
extra-config:
required: false
type: string
target-folder:
require: false
type: string

permissions:
contents: write

jobs:
build-and-deploy:
concurrency: publish-gh-pages
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Build Docs 🔧
uses: ./.github/workflows/build-docs
with:
target-folder: ${{ inputs.target-folder }}
extra-config: ${{ inputs.extra-config }}

- name: Deploy 🚀
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: build
force: false
target-folder: ${{ inputs.target-folder }}
clean-exclude: |
pr-preview/
version/
Loading

0 comments on commit d754856

Please sign in to comment.