|
19 | 19 | runs-on: ubuntu-latest |
20 | 20 | permissions: |
21 | 21 | 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 }} |
22 | 25 | steps: |
23 | 26 | - name: Checkout |
24 | 27 | uses: actions/checkout@v4 |
|
50 | 53 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
51 | 54 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
52 | 55 | 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 |
0 commit comments