perf: add dynamically loaded cache-dependencies for actions python

This reduces the main bundle size by ⚠️  1.28 MB minified! This bundle is loaded only when caching is enabled.

`setup-python` is used in [`setup-cpp`](https://github.com/aminya/setup-cpp) as a library. This optimization reduces the bundle size for that package as well. The build system of `setup-python` uses `ncc`, which doesn't immediately benefit from this change, but setup-cpp uses `Parcel`, which shows this huge improvement.

The reason for this huge reduction is that caching the dependencies uses the `@actions/cache` package, which is an extremely large package with big dependencies. The bundle size before this separation shows this:
![Screenshot_20230907_230625](https://github.com/actions/setup-python/assets/16418197/ec1baf34-85c3-459d-b8cf-894899959b2c)
This commit is contained in:
Amin Yahyaabadi 2023-09-07 23:17:53 -07:00
parent ffff3ab313
commit 96396ce7c5
27 changed files with 65 additions and 62 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -116,7 +116,7 @@
"prettier-config-atomic": "^3.1.0", "prettier-config-atomic": "^3.1.0",
"retry-as-promised": "^7.0.4", "retry-as-promised": "^7.0.4",
"semver": "7.5.4", "semver": "7.5.4",
"setup-python": "github:actions/setup-python#v4.7.0", "setup-python": "github:aminya/setup-python#a783db655c6e40317e2c0c96f9d162d9c9f4a751",
"shx": "0.3.4", "shx": "0.3.4",
"simple-update-notifier": "^2.0.0", "simple-update-notifier": "^2.0.0",
"terser-config-atomic": "^1.0.0", "terser-config-atomic": "^1.0.0",

View File

@ -147,8 +147,8 @@ importers:
specifier: 7.5.4 specifier: 7.5.4
version: 7.5.4 version: 7.5.4
setup-python: setup-python:
specifier: github:actions/setup-python#v4.7.0 specifier: github:aminya/setup-python#a783db655c6e40317e2c0c96f9d162d9c9f4a751
version: github.com/actions/setup-python/61a6322f88396a6271a6ee3565807d608ecaddd1 version: github.com/aminya/setup-python/a783db655c6e40317e2c0c96f9d162d9c9f4a751
shx: shx:
specifier: 0.3.4 specifier: 0.3.4
version: 0.3.4 version: 0.3.4
@ -10049,24 +10049,6 @@ packages:
readable-stream: 3.6.2 readable-stream: 3.6.2
dev: true dev: true
github.com/actions/setup-python/61a6322f88396a6271a6ee3565807d608ecaddd1:
resolution: {tarball: https://codeload.github.com/actions/setup-python/tar.gz/61a6322f88396a6271a6ee3565807d608ecaddd1}
name: setup-python
version: 4.0.0
dependencies:
'@actions/cache': 3.2.1
'@actions/core': 1.10.0
'@actions/exec': 1.1.1
'@actions/glob': 0.2.1
'@actions/http-client': 1.0.11
'@actions/io': 1.1.3
'@actions/tool-cache': 1.7.2
'@iarna/toml': 2.2.5
semver: 7.5.4
transitivePeerDependencies:
- encoding
dev: true
github.com/aminya/babel-plugin-remove-node-prefix/95fcbd92405b99a6eece48c493548996f12e6519(@babel/core@7.22.9): github.com/aminya/babel-plugin-remove-node-prefix/95fcbd92405b99a6eece48c493548996f12e6519(@babel/core@7.22.9):
resolution: {tarball: https://codeload.github.com/aminya/babel-plugin-remove-node-prefix/tar.gz/95fcbd92405b99a6eece48c493548996f12e6519} resolution: {tarball: https://codeload.github.com/aminya/babel-plugin-remove-node-prefix/tar.gz/95fcbd92405b99a6eece48c493548996f12e6519}
id: github.com/aminya/babel-plugin-remove-node-prefix/95fcbd92405b99a6eece48c493548996f12e6519 id: github.com/aminya/babel-plugin-remove-node-prefix/95fcbd92405b99a6eece48c493548996f12e6519
@ -10086,6 +10068,24 @@ packages:
'@actions/core': 1.10.0 '@actions/core': 1.10.0
dev: true dev: true
github.com/aminya/setup-python/a783db655c6e40317e2c0c96f9d162d9c9f4a751:
resolution: {tarball: https://codeload.github.com/aminya/setup-python/tar.gz/a783db655c6e40317e2c0c96f9d162d9c9f4a751}
name: setup-python
version: 4.0.0
dependencies:
'@actions/cache': 3.2.1
'@actions/core': 1.10.0
'@actions/exec': 1.1.1
'@actions/glob': 0.2.1
'@actions/http-client': 1.0.11
'@actions/io': 1.1.3
'@actions/tool-cache': 1.7.2
'@iarna/toml': 2.2.5
semver: 7.5.4
transitivePeerDependencies:
- encoding
dev: true
github.com/aminya/sort-package-json/076051b58be7b198732d1ce2b9a415ccd0c63a97: github.com/aminya/sort-package-json/076051b58be7b198732d1ce2b9a415ccd0c63a97:
resolution: {tarball: https://codeload.github.com/aminya/sort-package-json/tar.gz/076051b58be7b198732d1ce2b9a415ccd0c63a97} resolution: {tarball: https://codeload.github.com/aminya/sort-package-json/tar.gz/076051b58be7b198732d1ce2b9a415ccd0c63a97}
name: sort-package-json name: sort-package-json

View File

@ -5,20 +5,13 @@ import { info, warning } from "ci-log"
import { debug } from "@actions/core" import { debug } from "@actions/core"
import { join } from "patha" import { join } from "patha"
import { GITHUB_ACTIONS } from "ci-info" import { GITHUB_ACTIONS } from "ci-info"
import { isCacheFeatureAvailable, IS_MAC } from "setup-python/src/utils" import { IS_MAC } from "setup-python/src/utils"
import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"
import { pathExists } from "path-exists" import { pathExists } from "path-exists"
function isPyPyVersion(versionSpec: string) { function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith("pypy") return versionSpec.startsWith("pypy")
} }
export async function cacheDependencies(cache: string, pythonVersion: string) {
const cacheDependencyPath = undefined
const cacheDistributor = getCacheDistributor(cache, pythonVersion, cacheDependencyPath)
await cacheDistributor.restoreCache()
}
const checkLatest = false const checkLatest = false
export async function setupActionsPython(version: string, _setupDir: string, arch: string) { export async function setupActionsPython(version: string, _setupDir: string, arch: string) {
@ -45,9 +38,10 @@ export async function setupActionsPython(version: string, _setupDir: string, arc
info(`Successfully set up ${installed.impl} (${pythonVersion})`) info(`Successfully set up ${installed.impl} (${pythonVersion})`)
} }
if (isCacheFeatureAvailable()) { const cache = false
const cache = "pip" // package manager used for caching if (cache) {
await cacheDependencies(cache, pythonVersion) const { cacheDependencies } = await import("setup-python/src/cache-dependencies")
await cacheDependencies("pip", pythonVersion)
} }
} }