Skip to content

Commit

Permalink
Add automated publishing to gh-pages
Browse files Browse the repository at this point in the history
This change adds a Github workflow that builds the website and publishes
the build result to branch `gh-pages`.

Thus, effectively, this is the first step of changing the hosting of the
Theia website from Netlify to Github pages.

Therefore, we also requested a new Github secret for publishing
and eventually will request changing the target of theia-ide.org.
For more information see
https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues/3874
  • Loading branch information
planger authored and xai committed Dec 13, 2023
1 parent 4ca41d8 commit f42ad41
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy Website

on:
push:
branches: ["master"]
pull_request: # this is just for testing
workflow_dispatch:

# Allow only one concurrent deployment
concurrency:
group: "publish"

env:
WEBSITE_SOURCES_DIR: sources
WEBSITE_CONTENT_DIR: published
PREVIEW_FOLDER: ws-previews

jobs:
publish:
runs-on: ubuntu-latest
steps:

- name: Checkout website sources
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: ${{ env.WEBSITE_SOURCES_DIR }}

- name: Checkout content website
uses: actions/checkout@v4
with:
ref: gh-pages
token: ${{ secrets.GITHUB_TOKEN }}
path: ${{ env.WEBSITE_CONTENT_DIR }}

- name: Use Node.js 14.x
uses: actions/setup-node@v3
with:
node-version: 14.x
registry-url: 'https://registry.npmjs.org'

- name: Build website
working-directory: ${{ env.WEBSITE_SOURCES_DIR }}
run: npm install && npm run build

- name: Prune current content
working-directory: ${{ env.WEBSITE_CONTENT_DIR }}
run: git rm -rf * && [ -f ${{ env.PREVIEW_FOLDER }} ] && git checkout HEAD -- ${{ env.PREVIEW_FOLDER }}

- name: Copy content of website
working-directory: ${{ env.WEBSITE_SOURCES_DIR }}
run: cp -a public/. ../${{ env.WEBSITE_CONTENT_DIR }}

- name: Check for content changes
id: git-check
working-directory: ${{ env.WEBSITE_CONTENT_DIR }}
run: |
git add -A
echo "modified=$(if git diff --cached --exit-code --quiet; then echo 'false'; else echo 'true'; fi)" >> $GITHUB_OUTPUT
- name: Push content changes
if: steps.git-check.outputs.modified == 'true' && github.ref == 'refs/heads/master'
uses: peaceiris/actions-gh-pages@v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ${{ env.WEBSITE_CONTENT_DIR }}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ npm run serve
## CI

The website is automatically built at and deployed to Netlify.
A preview of each PR is deployed to Netlify.

In addition, every commit on `master` is built and published to branch `gh-pages`, which will soon replace the deployment of Netlify.
For more information, see [`publish.yml`](.github/workflows/publish.yml).

## License

Expand Down

0 comments on commit f42ad41

Please sign in to comment.