Skip to content

Update Dependencies #16

Update Dependencies

Update Dependencies #16

Workflow file for this run

# Update Unlayer Dependencies
#
# Checks npm for new versions of @unlayer/exporters and @unlayer/types
# and opens a PR to update the pnpm catalog if newer versions exist.
# Runs build + tests first and includes the result in the PR body.
#
# Runs daily and on manual dispatch.
name: Update Dependencies
on:
schedule:
- cron: '0 9 * * *' # daily at 9am UTC
workflow_dispatch:
# Prevent concurrent runs from racing on the same branch/PR
concurrency:
group: update-unlayer-deps
cancel-in-progress: true
jobs:
check-updates:
name: Check for updates
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.7.0
- name: Check for new versions
id: check
run: |
CATALOG="pnpm-workspace.yaml"
CHANGED=false
for PKG in "@unlayer/exporters" "@unlayer/types"; do
CURRENT=$(grep "\"$PKG\":" "$CATALOG" | sed 's/.*: *"\(.*\)"/\1/')
LATEST=$(npm view "$PKG" version 2>/dev/null || echo "")
if [ -z "$LATEST" ]; then
echo "⚠️ Could not fetch latest version for $PKG"
continue
fi
if [ "$CURRENT" != "$LATEST" ]; then
echo "📦 $PKG: $CURRENT → $LATEST"
sed -i "s|\"$PKG\": \"$CURRENT\"|\"$PKG\": \"$LATEST\"|" "$CATALOG"
CHANGED=true
else
echo "✅ $PKG: $CURRENT (up to date)"
fi
done
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
- name: Install dependencies
if: steps.check.outputs.changed == 'true'
run: pnpm install --no-frozen-lockfile
- name: Build and test
id: verify
if: steps.check.outputs.changed == 'true'
continue-on-error: true
run: |
set +e
pnpm build 2>&1
BUILD_EXIT=$?
if [ $BUILD_EXIT -ne 0 ]; then
echo "status=failed" >> $GITHUB_OUTPUT
echo "error=Build failed" >> $GITHUB_OUTPUT
exit 0
fi
pnpm test 2>&1
TEST_EXIT=$?
if [ $TEST_EXIT -ne 0 ]; then
echo "status=failed" >> $GITHUB_OUTPUT
echo "error=Tests failed" >> $GITHUB_OUTPUT
exit 0
fi
echo "status=passed" >> $GITHUB_OUTPUT
- name: Create or update PR
if: steps.check.outputs.changed == 'true'
run: |
# Use a fixed branch name so we always update the same PR
BRANCH="deps/update-unlayer"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Check if an open PR already exists for this branch
# Use // empty so jq returns nothing (not "null") when no PRs exist
EXISTING_PR=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number // empty')
if [ $? -ne 0 ]; then
echo "Error: failed to query existing pull requests"
exit 1
fi
# Fetch the remote branch if it exists
git fetch origin "$BRANCH" 2>/dev/null || true
# Both paths: create branch from current HEAD (main) with updated files
git checkout -B "$BRANCH"
git add pnpm-workspace.yaml pnpm-lock.yaml
# Skip if nothing changed (e.g., re-run with same versions already on branch)
if git diff --cached --quiet; then
echo "No changes to commit — already up to date"
exit 0
fi
git commit -m "deps: update @unlayer/exporters and @unlayer/types"
git push --force-with-lease origin "$BRANCH"
# Build PR body with test status
PACKAGES=$(grep '@unlayer' pnpm-workspace.yaml | sed 's/^ */- /')
STATUS="${{ steps.verify.outputs.status }}"
ERROR="${{ steps.verify.outputs.error }}"
if [ -z "$ERROR" ]; then
ERROR="Build or tests did not complete. See workflow logs for details."
fi
if [ "$STATUS" = "passed" ]; then
STATUS_LINE="✅ **Build & tests passed** — safe to merge."
else
STATUS_LINE="❌ **$ERROR** — check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details."
fi
BODY="${STATUS_LINE}"$'\n\n'"Updated packages (pnpm catalog):"$'\n'"${PACKAGES}"
if [ -n "$EXISTING_PR" ]; then
echo "Updating existing PR #$EXISTING_PR"
gh pr edit "$EXISTING_PR" --body "$BODY"
else
gh pr create \
--title "deps: update @unlayer/exporters and @unlayer/types" \
--body "$BODY" \
--base main \
--head "$BRANCH"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}