|
| 1 | +name: "Check if docs need an update" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "[0-9]+.[0-9]+" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +# Only one instance of this workflow will run on the same ref (PR/Branch/Tag) |
| 12 | +# Previous runs will be cancelled. |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + check-docs: |
| 19 | + name: Check if docs need an update |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + ref: ${{ github.ref }} |
| 26 | + # Need a complete fetch to make the master merge check work |
| 27 | + fetch-depth: 0 |
| 28 | + fetch-tags: true |
| 29 | + token: ${{ secrets.ALL_REPO_PAT }} |
| 30 | + |
| 31 | + - name: Setup git |
| 32 | + run: | |
| 33 | + # NOTE: The user email is {user.id}+{user.login}@users.noreply.github.com. |
| 34 | + # See users API: https://api.github.com/users/github-actions%5Bbot%5D |
| 35 | + git config user.name "github-actions[bot]" |
| 36 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 37 | + git fetch origin master |
| 38 | +
|
| 39 | + - uses: actions/setup-node@v5 |
| 40 | + with: |
| 41 | + node-version: 20 |
| 42 | + |
| 43 | + - name: Populate variables |
| 44 | + id: versions |
| 45 | + run: | |
| 46 | + . ./hooks/populate-hook-constants.sh |
| 47 | +
|
| 48 | + echo "packageVersion=$packageVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" |
| 49 | + echo "packageVersionXy=$packageVersionXy" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" |
| 50 | + echo "packageLockVersion=$packageLockVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" |
| 51 | + echo "packageLockVersionXy=$packageLockVersionXy" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" |
| 52 | + echo "newestVersion=$newestVersion" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" |
| 53 | + echo "targetBranch=$targetBranch" | tee -a "$GITHUB_OUTPUT" "$GITHUB_ENV" |
| 54 | +
|
| 55 | + - name: Check tag and branch correctness |
| 56 | + run: | |
| 57 | + if [[ "${{ steps.versions.outputs.packageVersion }}" != "${{ steps.versions.outputs.packageLockVersion }}" ]] |
| 58 | + then |
| 59 | + echo "The package version and package lock version do not match." |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + if [[ "refs/heads/${{ steps.versions.outputs.packageVersion }}" != ${{ github.ref }}* ]] |
| 64 | + then |
| 65 | + echo "Branch name and package version mismatch" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Install dependencies |
| 70 | + run: npm install |
| 71 | + |
| 72 | + - name: Build docs |
| 73 | + run: | |
| 74 | + npm run build-pretty |
| 75 | + npm run build-docs |
| 76 | +
|
| 77 | + - name: Check for changes in docs and create a commit if necessary |
| 78 | + run: | |
| 79 | + git update-index --really-refresh |
| 80 | +
|
| 81 | + if git diff-index --quiet HEAD; then |
| 82 | + # No-op, docs are updated |
| 83 | + else |
| 84 | + # Update docs and create a commit on the branch |
| 85 | + git add --all |
| 86 | + git commit -nm "doc: update docs for v${{ steps.versions.outputs.packageVersion }} tag" |
| 87 | + git push |
| 88 | + fi |
0 commit comments