From d37647e58ff93226fd235137568d061fb4e99afd Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Wed, 2 Oct 2024 16:33:30 -0700 Subject: [PATCH] CI: factor out `yarn install` dependencies We have a fixed set of setup we need to do to do `yarn install` (getting NodeJS, golang, and python toolchains; setting up the `M1` flag; etc.). Refactor those into a shared reusable workflow so it will be easier to change in the future. Signed-off-by: Mark Yen --- .github/actions/yarn-install/action.yaml | 43 +++++++++++++++ .github/workflows/docker-cli-monitor.yaml | 16 +----- .github/workflows/go-work-sync.yaml | 19 +------ .github/workflows/linux-e2e.yaml | 22 +------- .github/workflows/macM1-e2e.yaml | 30 +--------- .github/workflows/package.yaml | 58 +------------------- .github/workflows/rddepman.yaml | 18 +----- .github/workflows/release-merge-to-main.yaml | 21 +------ .github/workflows/screenshot.yaml | 20 +------ .github/workflows/test.yaml | 30 +--------- .github/workflows/ucmonitor.yaml | 18 +----- .github/workflows/upgrade-generate.yaml | 37 +------------ .github/workflows/windows-e2e.yaml | 23 +------- .github/workflows/wsl-helper-build.yaml | 58 -------------------- 14 files changed, 59 insertions(+), 354 deletions(-) create mode 100644 .github/actions/yarn-install/action.yaml delete mode 100644 .github/workflows/wsl-helper-build.yaml diff --git a/.github/actions/yarn-install/action.yaml b/.github/actions/yarn-install/action.yaml new file mode 100644 index 00000000000..6584d135709 --- /dev/null +++ b/.github/actions/yarn-install/action.yaml @@ -0,0 +1,43 @@ +name: Yarn Install +description: >- + This is a composite action that does everything needed to do `yarn install`. + +runs: + using: composite + steps: + # In case we're running on a self-hosted runner without `yarn` installed, + # set up NodeJS, enable `yarn`, and then handle the caching. + - uses: actions/setup-node@v4 + with: + node-version-file: package.json + - run: corepack enable yarn + shell: bash + - uses: actions/setup-node@v4 + with: + node-version-file: package.json + cache: yarn + + - uses: actions/setup-go@v5 + with: + go-version-file: go.work + cache-dependency-path: src/go/**/go.sum + + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + cache: pip + - run: pip install setuptools + shell: bash + + - name: Install Windows dependencies + if: runner.os == 'Windows' + shell: powershell + run: .\scripts\windows-setup.ps1 -SkipVisualStudio -SkipTools + + - name: Flag build for M1 + if: runner.os == 'macOS' && runner.arch == 'ARM64' + run: echo "M1=1" >> "${GITHUB_ENV}" + shell: bash + + - run: yarn install --frozen-lockfile + shell: bash diff --git a/.github/workflows/docker-cli-monitor.yaml b/.github/workflows/docker-cli-monitor.yaml index 50acb344743..20936ca018b 100644 --- a/.github/workflows/docker-cli-monitor.yaml +++ b/.github/workflows/docker-cli-monitor.yaml @@ -27,21 +27,7 @@ jobs: with: fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - run: yarn dcmonitor env: diff --git a/.github/workflows/go-work-sync.yaml b/.github/workflows/go-work-sync.yaml index 2a69d75de47..17a648d3662 100644 --- a/.github/workflows/go-work-sync.yaml +++ b/.github/workflows/go-work-sync.yaml @@ -39,30 +39,13 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 3 token: ${{ steps.get-token.outputs.token }} - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - - run: corepack enable - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: '**/go.sum' - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools + - uses: ./.github/actions/yarn-install - name: Determine go.mod files id: go-files run: >- printf "go-files=%s go.work\n" "$(git ls-files '**/go.mod' '**/go.sum' | tr '\r\n' ' ')" >> "$GITHUB_OUTPUT" - - run: yarn install --frozen-lockfile - run: yarn lint:go:fix - name: Check for changes id: changed diff --git a/.github/workflows/linux-e2e.yaml b/.github/workflows/linux-e2e.yaml index 4f8355ecec6..e58477b9f08 100644 --- a/.github/workflows/linux-e2e.yaml +++ b/.github/workflows/linux-e2e.yaml @@ -19,27 +19,7 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - # For compatibility with runners without yarn, we need to install node - # once, install yarn, then install node again to get caching. - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - - run: npm install --global yarn - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - name: Install dependencies - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - name: Disable admin-access before start up run: | mkdir -p $HOME/.config/rancher-desktop diff --git a/.github/workflows/macM1-e2e.yaml b/.github/workflows/macM1-e2e.yaml index d1554e83446..63b4bbe3d9d 100644 --- a/.github/workflows/macM1-e2e.yaml +++ b/.github/workflows/macM1-e2e.yaml @@ -17,35 +17,7 @@ jobs: with: persist-credentials: false ref: main - # For compatibility with runners without yarn, we need to install node - # once, install yarn, then install node again to get caching. - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - - run: npm install --global yarn - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - name: Install dependencies - run: yarn install --frozen-lockfile - #The next steps is a workaround for an unexpected failure in launching electron before running e2e tests - #Such failure is addressed in issue #2915 - - name: add tools to PATH - run: | - rm -fr $HOME/.rd/bin - mkdir -p $HOME/.rd/bin - cp -rf $HOME/actions-runner/_work/rancher-desktop/rancher-desktop/resources/darwin/bin/ $HOME/.rd/bin/ - export PATH="$HOME/.rd/bin:$PATH" + - uses: ./.github/actions/yarn-install - name: Disable admin-access before start up run: | mkdir -p $HOME/Library/Preferences/rancher-desktop diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml index 60c4babc053..50d06d861e6 100644 --- a/.github/workflows/package.yaml +++ b/.github/workflows/package.yaml @@ -55,28 +55,7 @@ jobs: persist-credentials: false # Needed to run `git describe` to get full version info fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - name: Install Windows dependencies - if: runner.os == 'Windows' - shell: powershell - run: .\scripts\windows-setup.ps1 -SkipVisualStudio -SkipTools - - name: Flag build for M1 - if: matrix.arch == 'aarch64' && matrix.platform == 'mac' - run: echo "M1=1" >> "${GITHUB_ENV}" - - run: pip install setuptools - - # Needs a network timeout for macos & windows. See https://github.com/yarnpkg/yarn/issues/8242 for more info - run: yarn install --frozen-lockfile --network-timeout 1000000 + - uses: ./.github/actions/yarn-install - run: yarn build - run: yarn package - name: Build bats.tar.gz @@ -166,24 +145,7 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - name: Install Windows dependencies - shell: powershell - run: .\scripts\windows-setup.ps1 -SkipVisualStudio -SkipTools - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - # Needs a network timeout for macos & windows. See https://github.com/yarnpkg/yarn/issues/8242 for more info - - run: yarn install --frozen-lockfile --network-timeout 1000000 + - uses: ./.github/actions/yarn-install - uses: actions/download-artifact@v4 name: Download artifact with: @@ -236,21 +198,7 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - # Needs a network timeout for macos & windows. See https://github.com/yarnpkg/yarn/issues/8242 for more info - - run: yarn install --frozen-lockfile --network-timeout 1000000 + - uses: ./.github/actions/yarn-install - uses: actions/download-artifact@v4 name: Download artifact with: diff --git a/.github/workflows/rddepman.yaml b/.github/workflows/rddepman.yaml index 1d663692672..18604206fef 100644 --- a/.github/workflows/rddepman.yaml +++ b/.github/workflows/rddepman.yaml @@ -29,23 +29,7 @@ jobs: with: fetch-depth: 0 - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - - run: pip install setuptools - - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - run: yarn rddepman env: diff --git a/.github/workflows/release-merge-to-main.yaml b/.github/workflows/release-merge-to-main.yaml index ce3b338c8b8..fcc7dcbd79c 100644 --- a/.github/workflows/release-merge-to-main.yaml +++ b/.github/workflows/release-merge-to-main.yaml @@ -32,26 +32,7 @@ jobs: contents: write steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - - run: corepack enable yarn - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - - run: yarn install --frozen-lockfile - + - uses: ./.github/actions/yarn-install - run: node scripts/ts-wrapper.js scripts/release-merge-to-main.ts env: GITHUB_WRITE_TOKEN: ${{ github.token }} diff --git a/.github/workflows/screenshot.yaml b/.github/workflows/screenshot.yaml index 53c9dc2780d..c4296507308 100644 --- a/.github/workflows/screenshot.yaml +++ b/.github/workflows/screenshot.yaml @@ -68,26 +68,8 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - - run: corepack enable yarn - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum + - uses: ./.github/actions/yarn-install - uses: ./.github/actions/setup-environment - - run: pip install setuptools - - # Needs a network timeout for macos & windows. See https://github.com/yarnpkg/yarn/issues/8242 for more info - run: yarn install --frozen-lockfile --network-timeout 1000000 - name: Override version if: inputs.mock_version run: echo "RD_MOCK_VERSION=${{ inputs.mock_version }}" >> "${GITHUB_ENV}" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7a7b975c493..f49f64117e6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,20 +13,7 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - run: pip install setuptools - - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - run: yarn build - run: yarn lint:nofix - name: Install shfmt @@ -48,18 +35,5 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - run: yarn lint:nofix diff --git a/.github/workflows/ucmonitor.yaml b/.github/workflows/ucmonitor.yaml index b434bbc9241..af84251b825 100644 --- a/.github/workflows/ucmonitor.yaml +++ b/.github/workflows/ucmonitor.yaml @@ -27,23 +27,7 @@ jobs: with: fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - - run: pip install setuptools - - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - run: yarn ucmonitor env: diff --git a/.github/workflows/upgrade-generate.yaml b/.github/workflows/upgrade-generate.yaml index 813a2996f91..01f1f710df1 100644 --- a/.github/workflows/upgrade-generate.yaml +++ b/.github/workflows/upgrade-generate.yaml @@ -23,27 +23,7 @@ jobs: persist-credentials: false # Needed to run `git describe` to get full version info fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - name: Install Windows dependencies - if: runner.os == 'Windows' - shell: powershell - run: .\scripts\windows-setup.ps1 -SkipVisualStudio -SkipTools - - name: Flag build for M1 - if: matrix.arch == 'aarch64' && matrix.platform == 'mac' - run: echo "M1=1" >> "${GITHUB_ENV}" - - run: pip install setuptools - - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - run: yarn build - run: yarn package - name: Upload Windows installer @@ -78,25 +58,12 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false + - uses: ./.github/actions/yarn-install - uses: actions/checkout@v4 with: ref: gh-pages path: pages persist-credentials: true - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - run: yarn install --frozen-lockfile - name: Download installer (msi) id: msi uses: actions/download-artifact@v4 diff --git a/.github/workflows/windows-e2e.yaml b/.github/workflows/windows-e2e.yaml index 5be1687428a..418cbe4918b 100644 --- a/.github/workflows/windows-e2e.yaml +++ b/.github/workflows/windows-e2e.yaml @@ -23,28 +23,7 @@ jobs: with: persist-credentials: false - uses: ./.github/actions/setup-environment - # For compatibility with runners without yarn, we need to install node - # once, install yarn, then install node again to get caching. - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - - run: corepack enable yarn - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache: 'true' - cache-dependency-path: src/go/**/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - name: Install dependencies - run: yarn install --frozen-lockfile + - uses: ./.github/actions/yarn-install - name: Run e2e Tests run: yarn test:e2e env: diff --git a/.github/workflows/wsl-helper-build.yaml b/.github/workflows/wsl-helper-build.yaml deleted file mode 100644 index 7b8304b3e07..00000000000 --- a/.github/workflows/wsl-helper-build.yaml +++ /dev/null @@ -1,58 +0,0 @@ -# This workflow builds the WSL Helper -name: 'GitHub Runner: WSL Helper' - -on: - #push: - # paths: [ src/go/wsl-helper/** ] - #pull_request: - # paths: [ src/go/wsl-helper/** ] - workflow_dispatch: - -permissions: - # This uses external actions, lock things down to read-only. - contents: read - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: yarn - - uses: actions/setup-go@v5 - with: - go-version-file: go.work - cache-dependency-path: src/go/wsl-helper/go.sum - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: pip - - run: pip install setuptools - - run: yarn install --frozen-lockfile - - name: Build Windows - run: go build . - working-directory: src/go/wsl-helper - env: - GOOS: windows - CGO_ENABLED: '0' - - name: Build Linux - run: go build . - working-directory: src/go/wsl-helper - env: - GOOS: linux - CGO_ENABLED: '0' - - uses: actions/upload-artifact@v4 - with: - name: wsl-helper-linux - path: src/go/wsl-helper/wsl-helper - if-no-files-found: error - - uses: golangci/golangci-lint-action@v6.1.0 - # This is only safe because this workflow does not allow writing - with: - args: --config=${{ github.workspace }}/.github/workflows/config/.golangci.yaml --verbose --timeout 3m - working-directory: src/go/wsl-helper - only-new-issues: true