Skip to content

Commit

Permalink
build(ci): configure nx migration with GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
KingDarBoja committed Jan 11, 2025
1 parent 30b6633 commit 60436bd
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
name: Test

description: Test if all the nx libraries and apps were affected after the nx migration.

# inputs:
# codecov_token:
# description: Codecov token
# required: true

runs:
using: composite

steps:
# - name: Format check
# shell: bash
# run: yarn nx format:check --base=main
- name: Lint
shell: bash
run: yarn nx affected:lint --base=main
- name: Build
shell: bash
run: yarn nx affected:build --base=main
# - name: Test
# shell: bash
# run: yarn nx affected:test --base=main -c=ci
# - name: E2E
# shell: bash
# run: yarn nx affected:e2e --base=main
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Perform check of nx dependencies and migrations if needed.
name: Nx Update Dependencies

on:
workflow_dispatch:
schedule:
# Every day at 6am UTC
- cron: '0 6 * * *'

jobs:
nx-migrate :
runs-on: ubuntu-latest

steps:
- name: Checkout commits
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup git user to "🤖 Nx Bot"
shell: bash
run: git config user.email "-" && git config user.name "🤖 Nx Bot"

# Setup NodeJS and dependencies
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.11.0'

- name: Install dependencies
shell: bash
run: yarn install --frozen-lockfile

# Nx workspace update steps.
- name: Check if @nx/workspace is outdated
id: nrwl-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.nrwl-workspace-outdated.outputs.outdated == 'true'
run: yarn nx migrate latest

- name: Install dependencies
if: steps.nrwl-workspace-outdated.outputs.outdated == 'true'
run: yarn install --no-immutable

- name: Check if has migrations
id: nrwl-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.nrwl-workspace-has-migrations.outputs.has_migrations == 'true'
run: yarn nx migrate --run-migrations

- name: Run @nx/workspace affected targets
id: test
if: steps.nrwl-workspace-outdated.outputs.outdated == 'true'
continue-on-error: true
uses: ./.github/actions/test
# with:
# codecov_token: ${{ secrets.CODECOV_TOKEN }}

- name: Commit changes
if: steps.nrwl-workspace-outdated.outputs.outdated == 'true'
run: |
LAST_VERSION=$(npm view @nx/workspace version)
git add .
[[ $(git status --porcelain) ]] && git commit -m "build: 📦 update nrwl workspace to ${LAST_VERSION}" || echo "nothing to commit"
- name: Remove migrations.json & commit
if: steps.nrwl-workspace-has-migrations.outputs.has_migrations == 'true'
run: |
git rm -f migrations.json
git commit -m "build: 📦 remove migrations.json"
- name: Push changes
if: steps.nrwl-workspace-outdated.outputs.outdated == 'true' && steps.test.outcome == 'success'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
force: true
tags: true

- name: Create PR
if: steps.nrwl-workspace-outdated.outputs.outdated == 'true' && steps.test.outcome != 'success'
run: |
LAST_VERSION=$(npm view @nx/workspace version)
BRANCH="update-nrwl-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 ${LAST_VERSION}" -b "Update @nx/workspace dependencies to ${LAST_VERSION}."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 60436bd

Please sign in to comment.