Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Build Docs Preview on PR #37

Merged
merged 23 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b0b165d
ci: manually perform gh-deploy
RobertRosca Jan 29, 2024
9f06721
ci: add workflows for creating/removing pr previews
RobertRosca Jan 29, 2024
392c6b9
ci(fix): set GIT_AUTHOR_ env vars as well
RobertRosca Jan 29, 2024
1d10215
ci: use gh cli to delete environment
RobertRosca Jan 30, 2024
243b1ab
ci(fix): add GH_TOKEN env var
RobertRosca Jan 30, 2024
6a0165f
ci(fix): remove '#' from environment name
RobertRosca Jan 30, 2024
ee8039f
ci: remove 'Closed' from docs pr close workflow name
RobertRosca Jan 30, 2024
9e774fd
ci(fix): add deployments write scope
RobertRosca Jan 30, 2024
068ec3d
ci rename clodes workflow to docs pr merged
RobertRosca Jan 30, 2024
66a9b0b
ci: revert to posting PR comments instead of dynamic environments
RobertRosca Jan 30, 2024
7fe6c41
ci: include diff in pr comment
RobertRosca Jan 30, 2024
aaabcd8
docs(ci): add short section on ci/cd to docs
RobertRosca Jan 30, 2024
922bbfe
ci: remove summary/diff
RobertRosca Jan 30, 2024
a75a9e9
ci: split pr into pr and cleanup files
RobertRosca Jan 30, 2024
8e0b0e6
ci: only give write permission when needed, output git status for deb…
RobertRosca Jan 30, 2024
7c8ff63
ci: only run rtd webhook on xfel org
RobertRosca Jan 30, 2024
8b4b735
docs: add section on user docs integration
RobertRosca Jan 30, 2024
00fea4d
ci: add concurrency rules
RobertRosca Jan 30, 2024
7667c63
ci(fix): fix typo - artifact not articat
RobertRosca Jan 30, 2024
1fe4313
ci(fix): remove duplicate workflow docs-pr-close.yml
RobertRosca Jan 30, 2024
3af265d
docs(ci): add description of `docs-pr-cleanup.yml`
RobertRosca Jan 30, 2024
c149545
fix(ci): lower case `url` env access
RobertRosca Jan 30, 2024
585a5a9
docs(ci): add placeholder sections on package and environment CIs
RobertRosca Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/docs-pr-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Docs - PR Cleanup

on:
pull_request:
types: [closed]

env:
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com

concurrency:
group: "pages-pr"
cancel-in-progress: true

jobs:
remove-preview-files:
runs-on: ubuntu-latest
outputs:
hash: ${{ steps.commit.outputs.hash }}
permissions:
contents: write
concurrency:
group: deploy
cancel-in-progress: false
steps:
- uses: actions/checkout@v3
with:
ref: gh-pages

- name: Remove Preview
run: |
git rm -rf pr/${{ github.event.number }}

- name: Commit and Push
id: commit
run: |
git commit \
-m "Remove Preview for PR#${{ github.event.number }}" \
-m "${{ github.event.pull_request.head.sha }}"
git push
echo "hash=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

comment-closed:
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs: remove-preview-files
steps:
- uses: marocchino/sticky-pull-request-comment@v2
with:
append: true
message: |
Preview removed on merge/PR close with ${{ needs.remove-preview-files.outputs.hash }}
73 changes: 73 additions & 0 deletions .github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Docs - PR

on:
pull_request:

env:
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com

concurrency:
group: "pages-pr--${{ github.ref }}"
cancel-in-progress: true

jobs:
build-and-upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/setup
with:
python-version: 3.8

- run: poetry run poe docs build

- uses: actions/upload-artifact@v4
with:
path: ./site

deploy:
runs-on: ubuntu-latest
needs: build-and-upload
permissions:
contents: write
concurrency:
group: deploy
cancel-in-progress: false
steps:
- uses: actions/checkout@v3
with:
ref: gh-pages

- uses: actions/download-artifact@v4

- name: Add/Update Preview
run: |
mkdir -p pr
rm -rf pr/${{ github.event.number }}
mv artifact pr/${{ github.event.number }}

- name: Commit and Push
run: |
git add --all pr/${{ github.event.number }}
git clean -fdx
git commit \
-m "Preview for PR#${{ github.event.number }}" \
-m "${{ github.event.pull_request.head.sha }}"
git push

comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
url: https://${{ github.repository_owner }}.github.io/${{github.event.repository.name}}/pr/${{ github.event.number }}
needs: deploy
steps:
- uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
View preview here - ${{ env.url }} (build for ${{ github.event.pull_request.head.sha }})
55 changes: 50 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name: Build and Deploy Documentation
name: Docs

on:
push:
branches:
- main

permissions:
contents: write
env:
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
build-and-upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -18,11 +25,49 @@ jobs:
with:
python-version: 3.8

- run: poetry run poe docs gh-deploy --force
- run: poetry run poe docs build

- uses: actions/upload-artifact@v4
with:
path: ./site

deploy:
runs-on: ubuntu-latest
needs: build-and-upload
permissions:
contents: write
concurrency:
group: deploy
cancel-in-progress: false
steps:
- uses: actions/checkout@v3
with:
ref: gh-pages

- name: Clean
run: |
rm -rf *
git checkout -- pr || true
git status -sb

- uses: actions/download-artifact@v4

- name: Update
run: |
mv artifact/* .
git status -sb

- name: Commit and Push
run: |
git add --all .
git clean -fdx
git commit -m "Update documentation for ${{ github.sha }}"
git push

rtd_webhook:
runs-on: ubuntu-latest
needs: deploy
if: github.repository_owner == 'European-XFEL'
steps:
- name: Trigger RTD User Documentation Webhook
run: curl -X POST ${{ secrets.RTD_USER_DOCS_WEBHOOK_URL }} -d 'token=${{ secrets.RTD_USER_DOCS_WEBHOOK_SECRET }}'
35 changes: 35 additions & 0 deletions docs/maintenance/ci-cd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CI/CD

## Documentation

The documentation is hosted with GitHub Pages, configured to deploy the contents of the `gh-pages` branch as a statically hosted web page.

There are two main workflows that are used to update the documentation:

1. `.github/workflows/docs.yml` - triggered on pushes to `main`, this will build the static site and push it to the `gh-pages` branch.
2. `.github/workflows/docs-pr.yml` - triggered on pull requests, this will build the static site, add it to a subdirectory `pr/<PR_NUMBER>`, and comment on the PR with a link to the preview. When the PR is closed, the directory is deleted.
3. `.github/workflows/docs-pr-cleanup.yml` - triggered on pull request close or merge, this will delete the preview directory.

### EuXFEL User Documentation Integration

The user documentation is hosted on EuXFEL RTD, it is 'integrated' with the environments documentation by including this repository as a submodule, which is then built as part of the user documentation build process.

To keep the two in sync, when the documentation is updated (merge/push to `main`) it triggers a RTD webhook to rebuild the user documentation, which will pull the latest version of the submodule.

For more information see:

- <https://github.com/European-XFEL/environments/pull/24>
- <https://git.xfel.eu/dataAnalysis/user-documentation/-/merge_requests/107>

## Package Builds

!!! warning "Work in Progress"

Some work done in:

- https://github.com/European-XFEL/environments/pull/30
- https://github.com/European-XFEL/environments/tree/feat/build-pkg-ci

## Environment Builds

!!! warning "Work in Progress"
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ nav:
- Environment Management: "maintenance/environments.md"
- Recipe Creation: "maintenance/recipes.md"
- Conda Installations: "maintenance/instances.md"
- CI/CD: "maintenance/ci-cd.md"
- Citing: "citing.md"

plugins:
Expand Down
Loading