Minor fix to doc publishing to GH Pages #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Code Checks | |
on: [push] | |
defaults: | |
run: | |
shell: bash | |
permissions: | |
contents: write | |
id-token: write | |
pages: write | |
jobs: | |
cleanliness: | |
name: Run Cleanliness Checks | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: './go.mod' | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.x | |
- run: pip install yamllint==1.33.0 | |
- run: | | |
make manifests | |
( cd test/fakepolicy && make manifests ) | |
make generate | |
make fmt | |
make vet | |
yamllint . | |
git diff --exit-code | |
# A separate job so that it can annotate the code | |
golangci: | |
name: Run golangci-lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: './go.mod' | |
- name: golangci-lint | |
uses: golangci/golangci-lint-action@v6 | |
with: | |
version: v1.58 | |
# Automatically uses ./.golangci.yml for configuration | |
tests: | |
name: Run Tests | |
runs-on: ubuntu-latest | |
# Prevent race conditions from multiple runs updating the wiki or GH pages. | |
# Additional runs will be queued as needed. | |
concurrency: | |
group: tests | |
cancel-in-progress: false | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: './go.mod' | |
- run: | | |
make test | |
grep -v 'zz_generated.deepcopy.go' raw-cover.out > cover.out | |
# This publishes a report and a badge in the wiki, which is useful for pull-requests. | |
- name: Update coverage report | |
uses: ncruces/go-coverage-report@v0 | |
with: | |
coverage-file: cover.out | |
output-dir: ${{ github.ref_name }} | |
report: true | |
chart: false | |
amend: false | |
continue-on-error: false | |
# The final steps publish the report, badge, and the (newly-generated) docs to GitHub Pages. | |
# They will only run when the branch is 'main' | |
- name: GH Pages - Setup | |
if: ${{ github.ref_name == 'main' }} | |
uses: actions/configure-pages@v5 | |
- name: GH Pages - Generate | |
if: ${{ github.ref_name == 'main' }} | |
run: | | |
go install golang.org/x/pkgsite/cmd/pkgsite@latest | |
echo "Starting the doc server..." | |
pkgsite 2>/dev/null & | |
DOC_PID=$! | |
sleep 15 # Let it initialize | |
echo "Downloading the generated doc site" | |
wget -r -q -np -N -E -p -k 'http://localhost:8080/open-cluster-management.io/[email protected]' || true | |
kill -9 $DOC_PID | |
echo "Bringing all the files into a gh-pages directory" | |
mv 'localhost:8080' 'gh-pages' | |
# Adjust some localhost links | |
find ./gh-pages -type f -name "*.html" -print0 | \ | |
xargs -0 sed -i 's|localhost:8080/files|broken-source-link|g' | |
find ./gh-pages -type f -name "*.html" -print0 | \ | |
xargs -0 sed -i 's|http://localhost:8080|https://pkg.go.dev|g' | |
# Copy these from the wiki (generated by ncruces/go-coverage-report) | |
cp ./.github/wiki/main/coverage.html gh-pages/coverage.html | |
cp ./.github/wiki/main/coverage.svg gh-pages/coverage.svg | |
# Add a simple redirect index.html | |
cat << EOF > gh-pages/index.html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Landing Page</title> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="refresh" content="0; URL=./open-cluster-management.io/governance-policy-nucleus.html" /> | |
</head> | |
<body> | |
<p>Redirecting to the docs page...</p> | |
</body> | |
</html> | |
EOF | |
- name: GH Pages - Upload | |
if: ${{ github.ref_name == 'main' }} | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: './gh-pages' | |
- name: GH Pages - Deploy | |
if: ${{ github.ref_name == 'main' }} | |
id: deployment | |
uses: actions/deploy-pages@v4 |