Skip to content

Commit

Permalink
Migrate action (#23)
Browse files Browse the repository at this point in the history
* add migrate github action

* trigger on PR

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* action update

* update e2e workflow

* Add note in contributing guide

* Fail e2e script when e2es fail
  • Loading branch information
isaacplmann authored Jun 19, 2023
1 parent 4200eda commit 9eb7512
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run e2e tests

on:
pull_request:
types: [synchronize, opened, reopened]

jobs:
e2e:
runs-on: ubuntu-latest
name: Run e2e tests
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 6.0.2

- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: E2E script
id: e2e-run
run: node e2e.js

- name: Report failure
if: ${{ failure() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
uses: ravsamhq/notify-slack-action@v2
with:
status: 'failure'
message_format: '{emoji} Workflow has {status_message} ${{ steps.e2e-run.outcome }}'
notification_title: '{workflow}'
footer: '<{run_url}|View Run> / Last commit <{commit_url}|{commit_sha}>'
mention_groups: '@Isaac'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
44 changes: 44 additions & 0 deletions .github/workflows/migrate-recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Migrate Recipes

on:
schedule:
- cron: "0 0 * * 0"

jobs:
migrate-recipes:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
name: Migrate Recipes
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 6.0.2

- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Migrate script
run: node migrate.js

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
base: main
title: Nx Migrate update
body: Update all recipes with nx migrate
commit-message: migrate recipes
branch: migrate-recipes
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ We'd love to have new examples being contributed to this repository.

Every example should live within a dedicated folder created at the root of this repository and being completely self-contained.

Make sure there is at least one e2e test in your example that verifies that the core functionality of your example actually works.

The folder should contain a `README.md` file with the following section

```markdown
Expand Down
40 changes: 40 additions & 0 deletions e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { execSync } = require("child_process");
const { readdirSync } = require("fs");

const BROKEN_RECIPES = [".git", ".github", "deno-deploy"];

function installPackages(cwd) {
const files = readdirSync(cwd);
if (files.includes("pnpm-lock.yaml")) {
execSync("pnpm i", { cwd });
} else if (files.includes("yarn-lock.json")) {
execSync("yarn", { cwd });
} else {
execSync("npm i --legacy-peer-deps", { cwd });
}
}

function runE2eTests(cwd) {
execSync("CI=true npx nx run-many --target=e2e --parallel=false", { cwd, stdio: [0,1,2] });
}

function processAllExamples() {
const files = readdirSync(".", { withFileTypes: true });
const failures = [];
files.forEach((file) => {
if (file.isDirectory() && !BROKEN_RECIPES.includes(file.name)) {
const cwd = "./" + file.name;
console.log(cwd);
try {
installPackages(cwd);
runE2eTests(cwd);
} catch (ex) {
failures.push(ex);
}
}
});
if (failures.length > 0) {
throw new Error('E2E Tests Failed');
}
}
processAllExamples();
51 changes: 51 additions & 0 deletions migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { execSync } = require("child_process");
const { readdirSync } = require("fs");

const BROKEN_RECIPES = [".git", ".github"];

function installPackages(cwd) {
console.log("Installing packages for " + cwd);
const files = readdirSync(cwd);
if (files.includes("pnpm-lock.yaml")) {
execSync("pnpm i", { cwd, stdio: [0, 1, 2] });
} else if (files.includes("yarn.lock")) {
execSync("yarn", { cwd, stdio: [0, 1, 2] });
} else {
execSync("npm ci --legacy-peer-deps", { cwd, stdio: [0, 1, 2] });
}
}
function migrateToLatest(cwd) {
console.log(`Migrating ${cwd}...`);
execSync("CI=true npx nx migrate latest", { cwd, stdio: [0, 1, 2] });
execSync("CI=true npx nx migrate --run-migrations --no-interactive", {
cwd,
stdio: [0, 1, 2],
timeout: 60000,
});
execSync("rm -rf migrations.json", { cwd, stdio: [0, 1, 2] });
console.log(`Done migrating ${cwd}.`);
}

function processAllExamples() {
const files = readdirSync(".", { withFileTypes: true });
let failedMigrations = [];
files.forEach((file) => {
if (file.isDirectory() && !BROKEN_RECIPES.includes(file.name)) {
const cwd = "./" + file.name;
installPackages(cwd);
try {
migrateToLatest(cwd);
} catch (ex) {
console.log(ex);
console.log("Continuing to next example...");
failedMigrations.push(cwd);
}
}
});
if (failedMigrations.length > 0) {
console.log(
"The following migrations failed: " + failedMigrations.join(", ")
);
}
}
processAllExamples();

0 comments on commit 9eb7512

Please sign in to comment.