Skip to content

nx migrate

nx migrate #4

Workflow file for this run

name: 'nx migrate'
on:
workflow_dispatch:
schedule:
# Every day at 6am UTC
- cron: '0 6 * * *'
jobs:
nx-migrate:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: setup node and pnpm
uses: dafnik/setup-node-pnpm@v2
with:
install-ignore-scripts: true
- name: Setup git user to "🤖 dfts-common Bot"
shell: bash
run: git config user.email "-" && git config user.name "🤖 dfts-common Bot"
- name: Check if @nx/workspace is outdated
id: nx-workspace-outdated
run: |
IS_OUTDATED=$(test ! -z "$(npm outdated @nx/workspace)" && echo true || echo false)
echo $IS_OUTDATED
echo "outdated=$IS_OUTDATED" >> $GITHUB_OUTPUT
- name: Update @nx/workspace
if: steps.nx-workspace-outdated.outputs.outdated == 'true'
run: pnpm nx migrate latest
- name: Install dependencies
if: steps.nx-workspace-outdated.outputs.outdated == 'true'
run: pnpm install --no-frozen-lockfile
- name: Check if has migrations
id: nx-workspace-has-migrations
run: |
HAS_MIGRATIONS=$(test -f migrations.json && echo true || echo false)
echo $HAS_MIGRATIONS
echo "has_migrations=$HAS_MIGRATIONS" >> $GITHUB_OUTPUT
- name: Run @nx/workspace migrations
if: steps.nx-workspace-has-migrations.outputs.has_migrations == 'true'
run: pnpm nx migrate --run-migrations
- name: Test
id: test
if: steps.nx-workspace-outdated.outputs.outdated == 'true'
continue-on-error: true
run: pnpm test
- name: Commit changes
if: steps.nx-workspace-outdated.outputs.outdated == 'true'
run: |
LAST_VERSION=$(npm view @nx/workspace version)
git add .
[[ $(git status --porcelain) ]] && git commit -m "build: update nx workspace to ${LAST_VERSION}" || echo "nothing to commit"
- name: Remove migrations.json & commit
if: steps.nx-workspace-has-migrations.outputs.has_migrations == 'true'
run: |
git rm -f migrations.json
git commit -m "build: remove migrations.json"
- name: Create PR
if: steps.nx-workspace-outdated.outputs.outdated == 'true'
run: |
LAST_VERSION=$(npm view @nx/workspace version)
BRANCH="update-nx-workspace-${LAST_VERSION}"
git checkout -b ${BRANCH}
git push -f --set-upstream origin ${BRANCH}
gh pr view ${BRANCH} || gh pr create -t "Update @nx/workspace to ${BRANCH}" -b "Update @nx/workspace dependencies to ${LAST_VERSION}."