|
| 1 | +name: Daily Build Zotero PDF.js Types |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + schedule: |
| 8 | + - cron: "0 0 * * *" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + check: |
| 13 | + name: Check if pdf.js changed |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + commit_hash: ${{ steps.get-latest-commit.outputs.short_commit }} |
| 17 | + need_build: ${{ steps.cache-hash.outputs.cache-hit != 'true' }} |
| 18 | + steps: |
| 19 | + - name: Get latest commit hash from Zotero/pdf.js |
| 20 | + id: get-latest-commit |
| 21 | + run: | |
| 22 | + latest_commit=$(git ls-remote https://github.com/zotero/pdf.js.git HEAD | cut -f1) |
| 23 | + echo "latest_commit=$latest_commit" >> $GITHUB_OUTPUT |
| 24 | + echo "short_commit=${latest_commit:0:7}" >> $GITHUB_OUTPUT |
| 25 | +
|
| 26 | + - name: Cache commit hash |
| 27 | + id: cache-hash |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: last_commit |
| 31 | + key: zotero-pdfjs-commit-${{ steps.get-latest-commit.outputs.latest_commit }} |
| 32 | + |
| 33 | + - name: Save new commit hash |
| 34 | + if: ${{ steps.cache-hash.outputs.cache-hit != 'true' }} |
| 35 | + run: | |
| 36 | + echo "${{ steps.get-latest-commit.outputs.latest_commit }}" > last_commit |
| 37 | +
|
| 38 | + build: |
| 39 | + name: Build pdf.js & extract types |
| 40 | + needs: check |
| 41 | + if: ${{ needs.check.outputs.need_build == 'true' }} |
| 42 | + runs-on: ubuntu-latest |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - name: Clone Zotero/pdf.js |
| 50 | + run: git clone https://github.com/zotero/pdf.js.git pdfjs |
| 51 | + |
| 52 | + - uses: actions/setup-node@v4 |
| 53 | + with: |
| 54 | + node-version: 20 |
| 55 | + cache: npm |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + run: npm install |
| 59 | + working-directory: pdfjs |
| 60 | + |
| 61 | + - name: Build pdf.js (gulp dist) |
| 62 | + run: npx gulp dist |
| 63 | + working-directory: pdfjs |
| 64 | + |
| 65 | + - name: Copy types to repo |
| 66 | + run: | |
| 67 | + rm -rf types |
| 68 | + mkdir -p types |
| 69 | + cp -r pdfjs/build/types/. types/ |
| 70 | + echo "${{ needs.check.outputs.commit_hash }}" > pdfjs-commit.txt |
| 71 | +
|
| 72 | + - name: Commit and push updated types |
| 73 | + run: | |
| 74 | + git config user.name "github-actions[bot]" |
| 75 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 76 | + git add types pdfjs-commit.txt |
| 77 | + if git diff --cached --quiet; then |
| 78 | + echo "✅ No changes to commit." |
| 79 | + else |
| 80 | + git commit -m "chore: update pdf.js types to commit ${{ needs.check.outputs.commit_hash }}" |
| 81 | + git push |
| 82 | + fi |
| 83 | +
|
| 84 | + # publish: |
| 85 | + # name: Publish to npm |
| 86 | + # needs: build |
| 87 | + # if: ${{ needs.check.outputs.need_build == 'true' }} |
| 88 | + # runs-on: ubuntu-latest |
| 89 | + # permissions: |
| 90 | + # contents: read |
| 91 | + # id-token: write |
| 92 | + |
| 93 | + # steps: |
| 94 | + # - uses: actions/checkout@v4 |
| 95 | + |
| 96 | + # - uses: pnpm/action-setup@v3 |
| 97 | + # with: |
| 98 | + # version: 9 |
| 99 | + |
| 100 | + # - uses: actions/setup-node@v4 |
| 101 | + # with: |
| 102 | + # node-version: 20 |
| 103 | + # registry-url: "https://registry.npmjs.org/" |
| 104 | + |
| 105 | + # - name: Install deps |
| 106 | + # run: pnpm install |
| 107 | + |
| 108 | + # - name: Bump patch version |
| 109 | + # run: | |
| 110 | + # current_version=$(node -p "require('./package.json').version") |
| 111 | + # new_version=$(node -p "const [M,m,p]=require('./package.json').version.split('.').map(Number);[M,m,p+1].join('.') ") |
| 112 | + # npm version $new_version --no-git-tag-version |
| 113 | + # git add package.json |
| 114 | + # git commit -m "chore: bump version to $new_version" |
| 115 | + # git push |
| 116 | + |
| 117 | + # - name: Publish package |
| 118 | + # run: npm publish --access public |
| 119 | + # env: |
| 120 | + # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments