Browse Source

ref: use our shared setup-volta (#40137)

I split this out to another repo such that `getsentry` could reuse it
anthony sottile 2 years ago
parent
commit
5cf5637efe

+ 0 - 32
.github/actions/setup-volta/action.yml

@@ -1,32 +0,0 @@
-name: 'volta setup'
-description: 'configures volta, node, yarn and caches'
-runs:
-  using: 'composite'
-  steps:
-    - name: setup-volta vars
-      id: vars
-      shell: bash
-      run: python3 -uS ${{ github.action_path }}/bin/setup-volta vars
-
-    - name: cache volta+node+yarn
-      id: cache
-      uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
-      with:
-        path: ${{ steps.vars.outputs.volta-dir }}
-        key: ${{ steps.vars.outputs.cache-key }}
-
-    - name: install volta+node+yarn
-      if: steps.cache.outputs.cache-hit != 'true'
-      shell: bash
-      run: python3 -uS ${{ github.action_path }}/bin/setup-volta install
-
-    - name: yarn cache dir
-      id: yarn
-      shell: bash
-      run: python3 -uS ${{ github.action_path }}/bin/setup-volta yarn-cache-dir
-
-    - name: cache yarn
-      uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
-      with:
-        path: ${{ steps.yarn.outputs.cache-dir }}
-        key: ${{ steps.vars.outputs.cache-key }}-${{ hashFiles('**/yarn.lock') }}

+ 0 - 104
.github/actions/setup-volta/bin/setup-volta

@@ -1,104 +0,0 @@
-#!/usr/bin/env python3
-import argparse
-import hashlib
-import io
-import json
-import os.path
-import secrets
-import subprocess
-import sys
-import tarfile
-import urllib.request
-
-VOLTA = "1.0.8"
-VOLTA_DIR = os.path.expanduser("~/.volta")
-VOLTA_BIN = os.path.join(VOLTA_DIR, "bin")
-
-URL = {
-    "darwin": f"https://github.com/volta-cli/volta/releases/download/v{VOLTA}/volta-{VOLTA}-macos.tar.gz",
-    "linux": f"https://github.com/volta-cli/volta/releases/download/v{VOLTA}/volta-{VOLTA}-linux-openssl-1.1.tar.gz",
-}
-SHA256 = {
-    "darwin": "b07461399f934b43bb34dfb0541eaf398537ccddcd2955166567459de52159dd",
-    "linux": "981b61a35e0070b0a998361cdbc9040c99b7fb64b6fee0cc2de52243a1851412",
-}
-
-
-def _volta_bin(exe: str) -> str:
-    return os.path.join(VOLTA_BIN, exe)
-
-
-def _command_vars() -> int:
-    with open("package.json") as f:
-        package_json = json.load(f)
-
-    node = package_json["volta"]["node"]
-    yarn = package_json["volta"]["yarn"]
-
-    cache_key = f"{sys.platform}-volta-{VOLTA}-node-{node}-yarn-{yarn}"
-
-    with open(os.environ["GITHUB_OUTPUT"], "a+") as f:
-        print(f"cache-key={cache_key}", file=f)
-        print(f"volta-dir={VOLTA_DIR}", file=f)
-
-    print(f"adding {VOLTA_BIN} to path")
-    with open(os.environ["GITHUB_PATH"], "a+") as f:
-        f.write(f"{VOLTA_BIN}\n")
-
-    print(f"adding VOLTA_HOME={VOLTA_DIR} to env")
-    with open(os.environ["GITHUB_ENV"], "a+") as f:
-        f.write(f"VOLTA_HOME={VOLTA_DIR}\n")
-
-    return 0
-
-
-def _command_install() -> int:
-    print("downloading...")
-    req = urllib.request.urlopen(URL[sys.platform], timeout=30)
-    bio = io.BytesIO(req.read())
-    checksum = hashlib.sha256(bio.getvalue()).hexdigest()
-    if not secrets.compare_digest(checksum, SHA256[sys.platform]):
-        print(f"volta checksum mismatch {checksum} {SHA256[sys.platform]}")
-        return 1
-
-    print("extracting...")
-    with tarfile.open(fileobj=bio) as tarf:
-        tarf.extractall(VOLTA_DIR)
-
-    print("setting up volta...")
-    if subprocess.call((os.path.join(VOLTA_DIR, "volta"), "setup")):
-        return 1
-
-    print("setting up node...")
-    if subprocess.call((_volta_bin("node"), "--version")):
-        return 1
-
-    print("setting up yarn...")
-    if subprocess.call((_volta_bin("yarn"), "--version")):
-        return 1
-
-    return 0
-
-
-def _command_yarn_cache_dir() -> int:
-    out = subprocess.check_output((_volta_bin("yarn"), "cache", "dir"))
-    cache_dir = out.decode().strip()
-    with open(os.environ["GITHUB_OUTPUT"], "a+") as f:
-        print(f"cache-dir={cache_dir}", file=f)
-    return 0
-
-
-def main() -> int:
-    parser = argparse.ArgumentParser()
-    parser.add_argument("command", choices=("vars", "install", "yarn-cache-dir"))
-    args = parser.parse_args()
-
-    return {
-        "vars": _command_vars,
-        "install": _command_install,
-        "yarn-cache-dir": _command_yarn_cache_dir,
-    }[args.command]()
-
-
-if __name__ == "__main__":
-    raise SystemExit(main())

+ 2 - 2
.github/workflows/acceptance.yml

@@ -67,7 +67,7 @@ jobs:
           # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
           fetch-depth: '2'
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       - name: Install dependencies
         run: yarn install --frozen-lockfile
@@ -136,7 +136,7 @@ jobs:
       - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e  # v2
         name: Checkout sentry
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       - name: Step configurations
         id: config

+ 1 - 1
.github/workflows/backend.yml

@@ -47,7 +47,7 @@ jobs:
     steps:
       - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e  # v2
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       - name: Setup sentry python env
         uses: ./.github/actions/setup-sentry

+ 1 - 1
.github/workflows/development-environment.yml

@@ -56,7 +56,7 @@ jobs:
           sudo /Applications/Docker.app/Contents/MacOS/Docker --unattended --install-privileged-components
           open -a /Applications/Docker.app --args --unattended --accept-license
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       # This handles Python's cache
       - name: Setup Python & cache

+ 2 - 2
.github/workflows/frontend.yml

@@ -56,7 +56,7 @@ jobs:
           app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
           private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       - name: Install dependencies
         id: dependencies
@@ -143,7 +143,7 @@ jobs:
     steps:
       - uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e  # v2
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       - name: Install dependencies
         run: yarn install --frozen-lockfile

+ 1 - 1
.github/workflows/openapi-diff.yml

@@ -44,7 +44,7 @@ jobs:
           repository: getsentry/sentry-api-schema
           path: sentry-api-schema
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
         if: steps.changes.outputs.api_docs == 'true'
 
       - name: Build OpenAPI Derefed JSON

+ 1 - 1
.github/workflows/openapi.yml

@@ -47,7 +47,7 @@ jobs:
           path: sentry-api-schema
           token: ${{ steps.getsentry.outputs.token }}
 
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
         if: steps.changes.outputs.api_docs == 'true'
 
       - name: Build OpenAPI Derefed JSON

+ 1 - 1
.github/workflows/sync-labels.yml

@@ -22,7 +22,7 @@ jobs:
       pull-requests: write
     steps:
       - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b  # v3
-      - uses: ./.github/actions/setup-volta
+      - uses: getsentry/action-setup-volta@d6f6ebfc4046feb3cfb6049e885185a01afd82b7  # v1.0.0
 
       - name: Install github-label-sync
         run: yarn global add github-label-sync@2.2.0