Skip to content

Commit

Permalink
Add cross-posting pages workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu authored Nov 15, 2022
1 parent 565a77f commit d3b026e
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Workflow to cross-post a jekyll site (or GitHub Pages)
# to another org/repo.
# Required secrets in repository consuming this workflow:
# - PAGES_ORGANIZATION: the target organization to publish
# pages to.
# - PAGES_ACCESS_TOKEN: a token that is valid in the target
# org/repo for pushing the resulting site
# - PAGES_REPOSITORY: optional repository name under the
# target organization. Defaults to source repo name.

name: pages
on:
workflow_dispatch:
push:
branches:
- main
- pages
- docs

env:
PAGES_ORGANIZATION: ${{ secrets.PAGES_ORGANIZATION }}
PAGES_REPOSITORY: ${{ secrets.PAGES_REPOSITORY }}

jobs:
gh-pages:
runs-on: ubuntu-latest
env:
PAGES_ORGANIZATION: ${{ secrets.PAGES_ORGANIZATION }}
PAGES_REPOSITORY: ${{ secrets.PAGES_REPOSITORY }}
PAGES_ACCESS_TOKEN: ${{ secrets.PAGES_ACCESS_TOKEN }}
steps:
- name: ✅ organization
if: env.PAGES_ORGANIZATION == ''
run: |
echo "::error title=PAGES_ORGANIZATION secret is required."
exit 1
- name: ✅ token
if: env.PAGES_ACCESS_TOKEN == ''
run: |
echo "::error title=PAGES_ACCESS_TOKEN secret is required."
exit 1
- name: 🤘 checkout
uses: actions/checkout@v2

- name: ⚙ jekyll
run: |
sudo gem install bundler
bundle install
- name: 🖉 default repo
if: env.PAGES_REPOSITORY == ''
run: echo "PAGES_REPOSITORY=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV

- name: 🙏 build
run: bundle exec jekyll build -b ${{ env.PAGES_REPOSITORY }}
env:
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: ✓ commit
run: |
cd _site
git init
git add -A
git config --local user.email "[email protected]"
git config --local user.name "[email protected]"
git commit -m "Publish pages from ${GITHUB_REPOSITORY}@${GITHUB_SHA:0:9}"
- name: 🚀 push
uses: ad-m/[email protected]
with:
github_token: ${{ env.PAGES_ACCESS_TOKEN }}
repository: ${{ env.PAGES_ORGANIZATION }}/${{ env.PAGES_REPOSITORY }}
branch: gh-pages
force: true
directory: ./_site

0 comments on commit d3b026e

Please sign in to comment.