Files
vagrant-libvirt/.github/workflows/publish-documentation-preview.yml
Darragh Bailey 8717eb6935 Explicity set action for preview action input (#1542)
GitHub actions have changed behaviour subtly in that
now setting the env is no longer sufficient for the
following action to pick up automatically.

Instead switch to being explicit.
2022-08-12 21:27:02 +00:00

76 lines
2.6 KiB
YAML

name: Deploy Docs Preview
on:
pull_request_target:
types:
- closed
- labeled
paths:
- 'docs/**'
permissions:
contents: write
pull-requests: write
jobs:
build-and-deploy:
if: ${{ github.event.action == 'closed' || (github.event.action == 'labeled' && github.event.label.name == 'preview-docs') }}
concurrency: publish-gh-pages
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Ruby
if: ${{ github.event.action == 'labeled' }}
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Install and Build 🔧
# don't allow a close to execute anything from the source code
if: ${{ github.event.action == 'labeled' }}
run: |
PR_NUMBER=$(jq -r ".number" "$GITHUB_EVENT_PATH")
REPO_NAME=$(jq -r ".repository.name" "$GITHUB_EVENT_PATH")
# 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
# 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 >> docs/_config.yml
repository_nwo: vagrant-libvirt/vagrant-libvirt
EOF
BUNDLE_GEMFILE=./docs/Gemfile bundle install
BUNDLE_GEMFILE=./docs/Gemfile bundle exec jekyll build --source docs/ --baseurl="/${REPO_NAME}/pr-preview/pr-${PR_NUMBER}" --destination build
- name: Set action
run: |
event_type=$(jq -r ".action" "$GITHUB_EVENT_PATH")
echo "event_type is $event_type"
case $event_type in
"labeled")
echo "action set to deploy"
echo "action=deploy" >> "$GITHUB_ENV"
;;
"closed")
echo "action set to remove"
echo "action=remove" >> "$GITHUB_ENV"
;;
*)
echo "unknown event type $event_type; no action to take"
echo "action=none" >> "$GITHUB_ENV"
;;
esac
- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
with:
action: ${{ env.action }}
source-dir: ./build/
preview-branch: gh-pages
umbrella-dir: pr-preview
- name: Remove label
uses: actions-ecosystem/action-remove-labels@v1
if: ${{ always() }}
with:
labels: preview-docs