withastro / action

A GitHub Action that deploys your Astro project to GitHub Pages
Other
143 stars 31 forks source link

Fix issue with packager installation if path is not repository root #31

Closed samrith-s closed 6 months ago

samrith-s commented 7 months ago

If you try to use this action with a path option specified other than ., the action fails with the following message:

Run withastro/action@v1
  with:
    path: docs
    package-manager: yarn
    node-version: 18
Run len=`echo $INPUT_PM | wc -c`
  len=`echo $INPUT_PM | wc -c`
  if [ $len -gt 1 ]; then
    PACKAGE_MANAGER=$(echo "$INPUT_PM" | grep -o '^[^@]*')
    VERSION=$(echo "$INPUT_PM" | grep -o '@.*' | sed 's/^@//')
    # Set default VERSION if not provided
    if [ -z "$VERSION" ]; then
        VERSION="latest"
    fi
    echo "PACKAGE_MANAGER=$PACKAGE_MANAGER" >> $GITHUB_ENV
  elif [ $(find "." -name "pnpm-lock.yaml") ]; then
      echo "PACKAGE_MANAGER=pnpm" >> $GITHUB_ENV
      echo "LOCKFILE=pnpm-lock.yaml" >> $GITHUB_ENV
  elif [ $(find "." -name "yarn.lock") ]; then 
      echo "PACKAGE_MANAGER=yarn" >> $GITHUB_ENV
      echo "LOCKFILE=yarn.lock" >> $GITHUB_ENV
  elif [ $(find "." -name "package-lock.json") ]; then 
      VERSION="latest"
      echo "PACKAGE_MANAGER=npm" >> $GITHUB_ENV
      echo "LOCKFILE=package-lock.json" >> $GITHUB_ENV
  elif [ $(find "." -name "bun.lockb") ]; then 
      VERSION="latest"
      echo "PACKAGE_MANAGER=bun" >> $GITHUB_ENV
      echo "LOCKFILE=bun.lockb" >> $GITHUB_ENV
  else
      echo "No lockfile found.
  Please specify your preferred \"package-manager\" in the action configuration."
      exit 1
  fi
  echo "VERSION=$VERSION" >> $GITHUB_ENV
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_PM: yarn
Error: Process completed with exit code 1.

This is because it tries to find a lock file in the root directory rather than in the directory specified in path. This PR aims to fix it.

samrith-s commented 7 months ago

Just have one question, are there any tests to ascertain if this works? Coz I was getting an error earlier which is what prompted me to make this PR.

Faf4a commented 7 months ago

I'm also still encountering this issue.

For documentation: https://github.com/aoijs/website/actions/runs/7152884666/job/19478704479

samrith-s commented 7 months ago

@Faf4a this has not been merged yet. Have you tried with this patch? Alternatively, I am using a completely custom deployment script which you can find here: https://github.com/samrith-s/concurrent-tasks/blob/main/.github/workflows/github-pages.yml

Faf4a commented 7 months ago

@Faf4a this has not been merged yet. Have you tried with this patch? Alternatively, I am using a completely custom deployment script which you can find here: https://github.com/samrith-s/concurrent-tasks/blob/main/.github/workflows/github-pages.yml

Oh, must've overlooked that. Thanks.

samrith-s commented 6 months ago

@natemoo-re Any update on this PR?

ionicsolutions commented 6 months ago

I just ran into the same issue when someone added additional NPM projects to a monorepo. Would love for this to get merged.

torn4dom4n commented 6 months ago

@Princesseuh I got an issue after this PR was merged.

Princesseuh commented 6 months ago

@Princesseuh I got an issue after this PR was merged.

It's not released yet, it's just merged

torn4dom4n commented 6 months ago

@Princesseuh I got an issue after this PR was merged.

It's not released yet, it's just merged

I see v1.0.4 release here and the last I try to run GitHub action it shows:

Secret source: Actions
Prepare workflow directory
Prepare all required actions
Getting action download info
Download action repository 'actions/checkout@v4' (SHA:b4ffde65f46336ab88eb53be808477a3936bae11)
Download action repository 'withastro/action@v1' (SHA:64c331d10da115fbaab6c13ceb8d64f06199a703)
Error: withastro/action/v1/action.yml (Line: 96, Col: 7): Unexpected value 'working-directory'
Error: GitHub.DistributedTask.ObjectTemplating.TemplateValidationException: The template is not valid. withastro/action/v1/action.yml (Line: 96, Col: 7): Unexpected value 'working-directory'
   at GitHub.DistributedTask.ObjectTemplating.TemplateValidationErrors.Check()
   at GitHub.Runner.Worker.ActionManifestManager.ConvertRuns(IExecutionContext executionContext, TemplateContext templateContext, TemplateToken inputsToken, String fileRelativePath, MappingToken outputs)
   at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile)
Error: Fail to load withastro/action/v1/action.yml

It's the lastest released.