From c5aff1b2f2ee100a2b93e6644170c557ff4fcd6f Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 10 Apr 2024 17:26:05 -0700 Subject: [PATCH] Make it possible to build npm with a linked language repo (#2214) This makes several changes: * It renames the `UPDATE_SASS_PROTOCOL` environment variable used by the Grinder `protobuf` task to `UPDATE_SASS_SASS_REPO` to make it more generic and so usable by other tasks. The previous name still works but is considered deprecated. * The `pkg-npm-*` grinder tasks now respects the `UPDATE_SASS_SASS_REPO` environment variable. This allows repos to ensure that the linked language repo's version of the TypeScript types are used when building the npm package. * `UPDATE_SASS_SASS_REPO=false` is set for all the `pkg-npm-*` tasks run by this repo, so that they will use the linked language repo's version of the TypeScript types. Co-authored-by: Carlos (Goodwine) <2022649+Goodwine@users.noreply.github.com> --- .github/util/initialize/action.yml | 2 +- .github/workflows/release.yml | 1 + .github/workflows/test.yml | 4 ++++ tool/grind.dart | 24 ++++++++++++++++++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/util/initialize/action.yml b/.github/util/initialize/action.yml index ea8c2f0cf..acfa759c2 100644 --- a/.github/util/initialize/action.yml +++ b/.github/util/initialize/action.yml @@ -32,5 +32,5 @@ runs: - name: Generate Dart from protobuf run: dart run grinder protobuf - env: {UPDATE_SASS_PROTOCOL: false} + env: {UPDATE_SASS_SASS_REPO: false} shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f7c60139..0fe1525f0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,6 +70,7 @@ jobs: - name: Deploy run: dart run grinder pkg-npm-deploy env: + UPDATE_SASS_SASS_REPO: false NPM_TOKEN: "${{ secrets.NPM_TOKEN }}" deploy_bazel: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa31b610e..38bedad96 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -113,6 +113,7 @@ jobs: - name: Build JS run: dart run grinder pkg-npm-dev + env: {UPDATE_SASS_SASS_REPO: false} - name: Check out Sass specification uses: sass/clone-linked-repo@v1 @@ -203,6 +204,7 @@ jobs: - name: Build JS run: dart run grinder pkg-npm-dev + env: {UPDATE_SASS_SASS_REPO: false} - name: Install built dependencies run: npm install @@ -282,6 +284,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: dart run grinder pkg-npm-dev + env: {UPDATE_SASS_SASS_REPO: false} - name: Run tests run: dart run test -t node -j 2 @@ -303,6 +306,7 @@ jobs: github-token: ${{ github.token }} - run: dart run grinder pkg-npm-dev + env: {UPDATE_SASS_SASS_REPO: false} - name: Run tests run: dart run test -p chrome -j 2 env: diff --git a/tool/grind.dart b/tool/grind.dart index 33b56ff2e..631bdebdf 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -213,8 +213,7 @@ String _readAndResolveMarkdown(String path) => File(path) /// Returns a map from JS type declaration file names to their contnets. Map _fetchJSTypes() { - var languageRepo = - cloneOrCheckout("https://github.com/sass/sass", "main", name: 'language'); + var languageRepo = _updateLanguageRepo(); var typeRoot = p.join(languageRepo, 'js-api-doc'); return { @@ -251,10 +250,7 @@ dart run protoc_plugin "\$@" run('chmod', arguments: ['a+x', 'build/protoc-gen-dart']); } - if (Platform.environment['UPDATE_SASS_PROTOCOL'] != 'false') { - cloneOrCheckout("https://github.com/sass/sass.git", "main", - name: 'language'); - } + _updateLanguageRepo(); await runAsync("buf", arguments: ["generate"], @@ -325,3 +321,19 @@ String _updateHomebrewLanguageRevision(String formula) { match.group(0)!.replaceFirst(match.group(1)!, languageRepoRevision) + formula.substring(match.end); } + +/// Clones the main branch of `github.com/sass/sass` and returns the path to the +/// clone. +/// +/// If the `UPDATE_SASS_SASS_REPO` environment variable is `false`, this instead +/// assumes the repo that already exists at `build/language/sass`. +/// `UPDATE_SASS_PROTOCOL` is also checked as a deprecated alias for +/// `UPDATE_SASS_SASS_REPO`. +String _updateLanguageRepo() => + // UPDATE_SASS_PROTOCOL is considered deprecated, because it doesn't apply as + // generically to other tasks. + Platform.environment['UPDATE_SASS_SASS_REPO'] != 'false' && + Platform.environment['UPDATE_SASS_PROTOCOL'] != 'false' + ? cloneOrCheckout("https://github.com/sass/sass.git", "main", + name: 'language') + : 'build/language';