Skip to content

Commit

Permalink
test prebuilt packages
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 12, 2024
1 parent 9e9e78f commit 7d7a330
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
34 changes: 23 additions & 11 deletions .github/workflows/ecosystem-ci-selected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ jobs:
with:
node-version: 20.14.0
id: setup-node

- name: Download built packages (branch)
if: inputs.refType == 'branch'
uses: dawidd6/action-download-artifact@v4
with:
repo: ${{ inputs.repo }}
branch: ${{ inputs.ref }}
name: packages
github_token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }}
path: built-packages
if_no_artifact_found: warn

- name: Download built packages (commit)
if: inputs.refType == 'commit'
uses: dawidd6/action-download-artifact@v4
with:
repo: ${{ inputs.repo }}
commit: ${{ inputs.ref }}
name: packages
github_token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }}
path: built-packages
if_no_artifact_found: warn

- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
Expand All @@ -72,14 +95,3 @@ jobs:
id: ecosystem-ci-run
env:
COREPACK_ENABLE_STRICT: 0
- if: always()
run: pnpm tsx discord-webhook.ts
env:
WORKFLOW_NAME: ci-selected
REF_TYPE: ${{ inputs.refType }}
REF: ${{ inputs.ref }}
REPO: ${{ inputs.repo }}
SUITE: ${{ inputs.suite }}
STATUS: ${{ job.status }}
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ workspace
.pnpm-debug.log
.idea
.verdaccio-cache
built-packages
61 changes: 43 additions & 18 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import actionsCore from '@actions/core'
const isGitHubActions = !!process.env.GITHUB_ACTIONS

let vuePath: string
let builtPath: string
let cwd: string
let env: ProcessEnv

Expand Down Expand Up @@ -101,6 +102,7 @@ export async function setupEnvironment(): Promise<EnvironmentData> {
const root = dirnameFrom(import.meta.url)
const workspace = path.resolve(root, 'workspace')
vuePath = path.resolve(workspace, 'core')
builtPath = path.resolve(root, 'built-packages')
cwd = process.cwd()
env = {
...process.env,
Expand Down Expand Up @@ -372,6 +374,7 @@ export async function getVuePackages() {
fs.readFileSync(`${directory}/package.json`, 'utf-8'),
)
return {
dirName: name,
directory,
packageJson,
}
Expand All @@ -380,8 +383,9 @@ export async function getVuePackages() {
.filter(({ packageJson }) => {
return !packageJson.private
})
.map(({ packageJson, directory }) => ({
.map(({ dirName, packageJson, directory }) => ({
name: packageJson.name,
dirName,
version: packageJson.version,
// if `build-vue` and `run-suites` are run separately, the version would already include commit hash
hashedVersion: packageJson.version.includes(commitHash)
Expand All @@ -404,29 +408,50 @@ function writeOrAppendNpmrc(dir: string, content: string) {
export async function buildVue({ verify = false, publish = false }) {
const packages = await getVuePackages()

cd(vuePath)
const install = getCommand('pnpm', 'install')
const runBuild = getCommand('pnpm', 'run', ['build', '--release'])
const runBuildDts = getCommand('pnpm', 'run', ['build-dts'])
const runTest = getCommand('pnpm', 'run', ['test'])
const hasBuilt = fs.existsSync(builtPath)

let s = performance.now()
if (!hasBuilt) {
const s = performance.now()

// Prefix with `corepack` because pnpm 7 & 8's lockfile formats differ
await $`corepack ${install}`
await $`${runBuild}`
await $`${runBuildDts}`
cd(vuePath)
const install = getCommand('pnpm', 'install')
const runBuild = getCommand('pnpm', 'run', ['build', '--release'])
const runBuildDts = getCommand('pnpm', 'run', ['build-dts'])
const runTest = getCommand('pnpm', 'run', ['test'])

// Prefix with `corepack` because pnpm 7 & 8's lockfile formats differ
await $`corepack ${install}`
await $`${runBuild}`
await $`${runBuildDts}`

if (verify) {
await $`${runTest}`
}

if (verify) {
await $`${runTest}`
console.log()
console.log(`Built in ${(performance.now() - s).toFixed(0)}ms`)
console.log()
} else {
console.log()
console.log(`Built packages found, copying...`)
console.log()
// copy built files into repo
for (const pkg of packages) {
const targetDir = path.join(pkg.directory, 'dist')
const fromDir = path.join(builtPath, pkg.dirName, 'dist')
const files = fs.readdirSync(fromDir)
if (fs.existsSync(targetDir)) {
fs.rmSync(targetDir, { recursive: true })
}
fs.mkdirSync(targetDir)
for (const f of files) {
fs.copyFileSync(path.join(fromDir, f), path.join(targetDir, f))
}
}
}

console.log()
console.log(`Built in ${(performance.now() - s).toFixed(0)}ms`)
console.log()

if (publish) {
s = performance.now()
const s = performance.now()

// TODO: prompt for `pnpm clean` if the same version already exists
// TODO: it's better to update the release script in the core repo than hacking it here
Expand Down

0 comments on commit 7d7a330

Please sign in to comment.