|
| 1 | +name: Deploy Docs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - Release |
| 7 | + types: |
| 8 | + - completed |
| 9 | + branches: |
| 10 | + - main |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: deploy-docs |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +jobs: |
| 21 | + deploy-docs: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: github.event_name == 'workflow_dispatch' || contains(fromJSON('["success","skipped"]'), github.event.workflow_run.conclusion) |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v6 |
| 26 | + with: |
| 27 | + ref: main |
| 28 | + |
| 29 | + - name: Use Node.js 24.x |
| 30 | + uses: actions/setup-node@v6 |
| 31 | + with: |
| 32 | + node-version: 24.x |
| 33 | + registry-url: https://registry.npmjs.org |
| 34 | + |
| 35 | + - name: Setup pnpm |
| 36 | + uses: pnpm/action-setup@v4 |
| 37 | + |
| 38 | + - name: Use latest published package |
| 39 | + run: | |
| 40 | + package_version="$(node -p "require('./package.json').version")" |
| 41 | + latest_version="$(npm view react-easy-crop version)" |
| 42 | +
|
| 43 | + for attempt in {1..18}; do |
| 44 | + if [ "$latest_version" = "$package_version" ]; then |
| 45 | + break |
| 46 | + fi |
| 47 | +
|
| 48 | + echo "npm latest is ${latest_version}; waiting for ${package_version} (${attempt}/18)" |
| 49 | + sleep 10 |
| 50 | + latest_version="$(npm view react-easy-crop version)" |
| 51 | + done |
| 52 | +
|
| 53 | + if [ "$latest_version" != "$package_version" ]; then |
| 54 | + echo "::warning::Expected npm latest ${package_version}, got ${latest_version}; deploying docs with npm latest." |
| 55 | + fi |
| 56 | +
|
| 57 | + REACT_EASY_CROP_VERSION="$latest_version" node <<'NODE' |
| 58 | + const fs = require('fs') |
| 59 | +
|
| 60 | + const path = 'docs/package.json' |
| 61 | + const pkg = JSON.parse(fs.readFileSync(path, 'utf8')) |
| 62 | + pkg.dependencies['react-easy-crop'] = process.env.REACT_EASY_CROP_VERSION |
| 63 | + fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`) |
| 64 | + NODE |
| 65 | + echo "Using react-easy-crop@${latest_version}" |
| 66 | +
|
| 67 | + - name: Install docs dependencies |
| 68 | + run: pnpm --dir docs install --no-frozen-lockfile --ignore-scripts |
| 69 | + |
| 70 | + - name: Deploy docs to GitHub Pages |
| 71 | + run: pnpm --dir docs deploy |
| 72 | + env: |
| 73 | + CURRENT_BRANCH: main |
| 74 | + GIT_PASS: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + GIT_USER: github-actions[bot] |
| 76 | + GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com |
| 77 | + GIT_USER_NAME: github-actions[bot] |
| 78 | + USE_SSH: false |
0 commit comments