Skip to content

Commit

Permalink
Merge branch 'main' into feat/suspense-router
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 authored Jun 7, 2023
2 parents 7350273 + 4b56e67 commit 447e863
Show file tree
Hide file tree
Showing 184 changed files with 6,561 additions and 4,974 deletions.
104 changes: 104 additions & 0 deletions .github/actions/actionsLib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* eslint-env node */
// @ts-check

import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { getExecOutput } from '@actions/exec'
import { hashFiles } from '@actions/glob'

/**
* @typedef {import('@actions/exec').ExecOptions} ExecOptions
*/

export const REDWOOD_FRAMEWORK_PATH = fileURLToPath(new URL('../../', import.meta.url))

/**
* @param {string} command
* @param {ExecOptions} options
*/
function execWithEnv(command, { env = {}, ...rest } = {}) {
return getExecOutput(
command,
undefined,
{
// @ts-expect-error TS doesn't like spreading process.env here but it's fine for our purposes.
env: {
...process.env,
...env
},
...rest
}
)
}

/**
* @param {string} cwd
*/
export function createExecWithEnvInCwd(cwd) {
/**
* @param {string} command
* @param {Omit<ExecOptions, 'cwd'>} options
*/
return function (command, options = {}) {
return execWithEnv(command, { cwd, ...options })
}
}

export const execInFramework = createExecWithEnvInCwd(REDWOOD_FRAMEWORK_PATH)

/**
* @param {string} redwoodProjectCwd
*/
export function projectDeps(redwoodProjectCwd) {
return execInFramework('yarn project:deps', { env: { RWJS_CWD: redwoodProjectCwd } })
}

/**
* @param {string} redwoodProjectCwd
*/
export function projectCopy(redwoodProjectCwd) {
return execInFramework('yarn project:copy', { env: { RWJS_CWD: redwoodProjectCwd } })
}

/**
* @param {string} prefix
*/
export async function createCacheKeys(prefix) {
const baseKey = [
prefix,
process.env.RUNNER_OS,
// @ts-expect-error not sure how to change the lib compiler option to es2021+ here.
process.env.GITHUB_REF.replaceAll('/', '-'),
await hashFiles(path.join('__fixtures__', 'test-project'))
].join('-')

// const testProjectKey = [
// ]

const dependenciesKey = [
baseKey,
'dependencies',
await hashFiles(['yarn.lock', '.yarnrc.yml'].join('\n')),
].join('-')

const distKey = [
dependenciesKey,
'dist',
await hashFiles([
'package.json',
'babel.config.js',
'tsconfig.json',
'tsconfig.compilerOption.json',
'nx.json',
'lerna.json',
'packages',
].join('\n'))
].join('-')

return {
baseKey,
dependenciesKey,
distKey
}
}
2 changes: 1 addition & 1 deletion .github/actions/check_create_redwood_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1"
},
"packageManager": "yarn@3.5.1"
"packageManager": "yarn@3.6.0"
}
2 changes: 1 addition & 1 deletion .github/actions/check_test_project_fixture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1"
},
"packageManager": "yarn@3.5.1"
"packageManager": "yarn@3.6.0"
}
2 changes: 1 addition & 1 deletion .github/actions/only_doc_changes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1"
},
"packageManager": "yarn@3.5.1"
"packageManager": "yarn@3.6.0"
}
36 changes: 0 additions & 36 deletions .github/actions/set-up-job/action.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .github/actions/set-up-test-project/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Set up test project
description: Sets up the test project fixture in CI for smoke tests and CLI checks

runs:
# `node18` isn't supported yet
using: node16
main: 'setUpTestProject.mjs'

outputs:
test-project-path:
description: Path to the test project
111 changes: 111 additions & 0 deletions .github/actions/set-up-test-project/setUpTestProject.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* eslint-env node */
// @ts-check

import path from 'node:path'

import cache from '@actions/cache'
import core from '@actions/core'

import fs from 'fs-extra'

import {
createCacheKeys,
createExecWithEnvInCwd,
projectCopy,
projectDeps,
REDWOOD_FRAMEWORK_PATH,
} from '../actionsLib.mjs'

const TEST_PROJECT_PATH = path.join(
path.dirname(process.cwd()),
'test-project'
)

core.setOutput('test-project-path', TEST_PROJECT_PATH)

const {
dependenciesKey,
distKey
} = await createCacheKeys('test-project')

/**
* @returns {Promise<void>}
*/
async function main() {
const distCacheKey = await cache.restoreCache([TEST_PROJECT_PATH], distKey)

if (distCacheKey) {
console.log(`Cache restored from key: ${distKey}`)
return
}

const dependenciesCacheKey = await cache.restoreCache([TEST_PROJECT_PATH], dependenciesKey)

if (dependenciesCacheKey) {
console.log(`Cache restored from key: ${dependenciesKey}`)
await sharedTasks()
} else {
console.log(`Cache not found for input keys: ${distKey}, ${dependenciesKey}`)
await setUpTestProject()
}

await cache.saveCache([TEST_PROJECT_PATH], distKey)
console.log(`Cache saved with key: ${distKey}`)
}

/**
* @returns {Promise<void>}
*/
async function setUpTestProject() {
const TEST_PROJECT_FIXTURE_PATH = path.join(
REDWOOD_FRAMEWORK_PATH,
'__fixtures__',
'test-project'
)

console.log(`Creating project at ${TEST_PROJECT_PATH}`)
console.log()
await fs.copy(TEST_PROJECT_FIXTURE_PATH, TEST_PROJECT_PATH)

console.log(`Adding framework dependencies to ${TEST_PROJECT_PATH}`)
await projectDeps(TEST_PROJECT_PATH)
console.log()

console.log(`Installing node_modules in ${TEST_PROJECT_PATH}`)
await execInProject('yarn install')
console.log()

await cache.saveCache([TEST_PROJECT_PATH], dependenciesKey)
console.log(`Cache saved with key: ${dependenciesKey}`)

await sharedTasks()
}

const execInProject = createExecWithEnvInCwd(TEST_PROJECT_PATH)

/**
* @returns {Promise<void>}
*/
async function sharedTasks() {
console.log('Copying framework packages to project')
await projectCopy(TEST_PROJECT_PATH)
console.log()

console.log('Generating dbAuth secret')
const { stdout } = await execInProject(
'yarn rw g secret --raw',
{ silent: true }
)
fs.appendFileSync(
path.join(TEST_PROJECT_PATH, '.env'),
`SESSION_SECRET='${stdout}'`
)
console.log()

console.log('Running prisma migrate reset')
await execInProject(
'yarn rw prisma migrate reset --force',
)
}

main()
37 changes: 37 additions & 0 deletions .github/actions/set-up-yarn-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Set up yarn cache
description: |
Sets up caching for yarn install steps.
Caches yarn's cache directory, install state, and node_modules.
runs:
using: composite

steps:
# We try to cache and restore yarn's cache directory and install state to speed up the yarn install step.
# Caching yarn's cache directory avoids its fetch step.
- name: 📁 Get yarn cache directory
id: get-yarn-cache-directory
run: echo "CACHE_DIRECTORY=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
shell: bash

# If the primary key doesn't match, the cache will probably be stale or incomplete,
# but still worth restoring for the yarn install step.
- name: ♻️ Restore yarn cache
uses: actions/cache@v3
with:
path: ${{ steps.get-yarn-cache-directory.outputs.CACHE_DIRECTORY }}
key: yarn-cache-${{ runner.os }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
restore-keys: yarn-cache-${{ runner.os }}

# We avoid restore-keys for these steps because it's important to just start from scratch for new PRs.
- name: ♻️ Restore yarn install state
uses: actions/cache@v3
with:
path: .yarn/install-state.gz
key: yarn-install-state-${{ runner.os }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}

- name: ♻️ Restore node_modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: yarn-node-modules-${{ runner.os }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
9 changes: 0 additions & 9 deletions .github/actions/setup_test_project/action.yaml

This file was deleted.

35 changes: 0 additions & 35 deletions .github/actions/setup_test_project/setup_test_project.mjs

This file was deleted.

3 changes: 2 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"is-port-reachable",
"pretty-ms",
"camelcase",
"sort-package-json"
"sort-package-json",
"@redwoodjs/vite"
]
}
Loading

0 comments on commit 447e863

Please sign in to comment.