felixmosh / turborepo-gh-artifacts

A TurboRepo local cache server which uploads artifact cache to GH artifacts.
MIT License
122 stars 7 forks source link

GitHub Action issue [Need help] #21

Closed NorkzYT closed 1 year ago

NorkzYT commented 1 year ago

Hello, hope you are having a wonderful day.

I copied https://github.com/felixmosh/turborepo-gh-artifacts-example/blob/master/.github/workflows/test.yaml, and ran it with the requirements this repositories README.md says, I receive Unknown or unexpected option: --api during Build. Could someone please assist me with this setup as I am certain it is incorrect?

The TurboRepo.yml file contents are displayed below.

name: TurboRepo Github Artifacts action

on:
  workflow_dispatch:
  push:
    branches:
      - main
jobs:
  turborepo-github-artifacts-action:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Cache node_modules
        uses: actions/cache@v3
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install Packages
        run: yarn install --frozen-lockfile
        env:
          CI: true

      - name: Turborepo local server
        uses: felixmosh/turborepo-gh-artifacts@v2
        with:
          repo-token: ${{ secrets.TOKEN_TURBOREPO }} # GITHUB_TOKEN
          server-token: ${{ secrets.TURBO_SERVER_TOKEN }}

      - name: Build
        run: yarn build --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team="team_name"
felixmosh commented 1 year ago

Hi, What is your build script does?

NorkzYT commented 1 year ago

The output of the Build is displayed below.

Run yarn build --api="http://127.0.0.1:9080" --token="***" --team="team_name"
  yarn build --api="http://127.0.0.1:9080" --token="***" --team="team_name"
  shell: /usr/bin/bash -e {0}
yarn run v1.22.19
warning team_name@0.0.0: The engine "pnpm" appears to be invalid.
$ next build --api=http://127.0.0.1:9080 --token=*** --team=team_name
Unknown or unexpected option: --api
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

I am going to change the Build based on the new README.md changes, will advise.

felixmosh commented 1 year ago

It is not related to the new (env vars usage) feature.

I think that your yarn build doesn't uses turborepo command.

NorkzYT commented 1 year ago

Understood, I changed the command.

I now receive the following output.

Run yarn build-turbo

yarn run v1.22.19
warning repository@0.0.0: The engine "pnpm" appears to be invalid.
$ turbo run build
• Running build
build: ERROR: command finished with error: exec: "pnpm": executable file not found in $PATH
• Remote caching disabled
exec: "pnpm": executable file not found in $PATH
 ERROR  run failed: command  exited (1)
build: cache miss, executing f257ee3b340b7d93

 Tasks:    0 successful, 1 total
Cached:    0 cached, 1 total
  Time:    322ms 

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

I am thinking the pnpm error is due to the following in my package.json file.

  "engines": {
    "pnpm": ">=7.17.0",
    "npm": ">=7.10.0",
    "node": ">=16.0.0"
  }

Yarn is not installed, I am going to change the yarn command to pnpm.

felixmosh commented 1 year ago

Is it working on the local? the error is not related to this lib.

NorkzYT commented 1 year ago

I fixed the Github action by setting upPNPM instead of Yarn.

The following yml contains the contents of the currently working PNPM TurboRepo GitHub Artifacts Action.

name: TurboRepo Github Artifacts action

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  turborepo-github-artifacts-action:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        id: pnpm-install
        with:
          version: 7
          run_install: false

      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - name: Install Packages
        run: pnpm install --frozen-lockfile
        env:
          CI: true

      - name: Turborepo local server
        uses: felixmosh/turborepo-gh-artifacts@v2
        with:
          repo-token: ${{ secrets.TOKEN_TURBOREPO }} # GITHUB_TOKEN
          server-token: ${{ secrets.TURBO_SERVER_TOKEN }}

      - name: Build
        run: pnpm run build-turbo
        env:
          TURBO_API: 'http://127.0.0.1:9080'
          TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
          TURBO_TEAM: 'foo'
NorkzYT commented 1 year ago

By following the instructions in the example repository, will I be able to connect to the GitHub Artifacts Turbo Repo Cache?

https://github.com/felixmosh/turborepo-gh-artifacts-example#remote-caching

felixmosh commented 1 year ago

What do you mean? this is what the lib does, proxy between turborepo remote-cache feature to Github Artifacts in order to save build artifacts there.

NorkzYT commented 1 year ago

Understood. Every time I run the build-turbo command, will it automatically connect to the GitHub TurboRepo Cache when running it with the following parameters?

turbo run build --api="https://my-server.example.com" --token="xxxxxxxxxxxxxxxxx"
felixmosh commented 1 year ago

Yeah :] This is the whole point, the flow is as the following:

  1. state: no cache artifacts
  2. run build -> generates cache artifacts, the lib saves them to GithubArtifacts

Now, if you will build the same app (which should produce the same cache artifacts), turbo repo will download the artifacts using this lib from GithubArtifacts, and reuse it. (won't build them at all)

NorkzYT commented 1 year ago

Understood, thank you very much for the explanation.