Skip to content

Commit 5a2d8aa

Browse files
committed
Add steps to publish content archive to GitHub Pages
1 parent 2663c5a commit 5a2d8aa

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

.github/workflows/build.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
runs-on: ubuntu-latest
2020
permissions:
2121
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
22+
outputs:
23+
ref_name: ${{ steps.set-vars.outputs.ref_name }}
24+
commit_sha: ${{ steps.set-vars.outputs.commit_sha }}
2225
steps:
2326
- name: Checkout
2427
uses: actions/checkout@v4
@@ -50,3 +53,61 @@ jobs:
5053
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
5154
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5255
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
56+
57+
- name: Upload build artifacts
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: build-artifacts
61+
path: target/classes
62+
63+
- name: Set ref_name and commit_sha
64+
id: set-vars
65+
run: |
66+
echo "::set-output name=ref_name::${{ github.ref_name }}"
67+
echo "::set-output name=commit_sha::${{ github.sha }}"
68+
69+
deploy-to-gh-pages:
70+
name: Deploy to GitHub Pages
71+
runs-on: ubuntu-latest
72+
needs: build
73+
# Execute this stage only for main and tags
74+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
75+
permissions:
76+
contents: write
77+
steps:
78+
- name: Checkout gh-pages branch
79+
uses: actions/checkout@v4
80+
with:
81+
ref: gh-pages
82+
fetch-depth: 0
83+
84+
- name: Define target_data_dir
85+
id: set-target-dir
86+
run: echo "target_data_dir=data/${{ needs.build.outputs.ref_name }}" >> $GITHUB_ENV
87+
88+
- name: Remove old content
89+
run: |
90+
git clean -fd
91+
git reset --hard
92+
rm -rf "${{ env.target_data_dir }}"
93+
94+
- name: Download build artifacts
95+
uses: actions/download-artifact@v4
96+
with:
97+
name: build-artifacts
98+
path: "${{ env.target_data_dir }}"
99+
100+
- name: Generate data/index.json
101+
run: |
102+
find data -name "index.json" | sort | while IFS= read -r indexJsonFile; do
103+
relative_path="$(echo "${indexJsonFile}" | sed -E 's,^data/,,')"
104+
jq --arg file "$relative_path" '.specification | {($file): {title: .title, version: .version, scmRevisionDate: .scmRevisionDate, scmRevisionNumber: .scmRevisionNumber}}' "$indexJsonFile"
105+
done | jq -s 'add' > data/index.json
106+
107+
- name: Commit and push changes
108+
run: |
109+
git config user.name "github-actions[bot]"
110+
git config user.email "github-actions[bot]@users.noreply.github.com"
111+
git add "${{ env.target_data_dir }}" "data/index.json"
112+
git commit -m "Deploy ${{ env.target_data_dir }} to GitHub Pages" -m "(from #${{ needs.build.outputs.commit_sha }})"
113+
git push origin gh-pages

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ dependency-reduced-pom.xml
1313

1414
# Ignore IDE files
1515
*.iml
16+
17+
# Data directory is only for `gh-pages` branch
18+
/data/

0 commit comments

Comments
 (0)