AlexxNB / caprover-action

Action to deploy on Caprover server.
MIT License
31 stars 20 forks source link

Cannot find hash of last commit on branch "main" #4

Open Alwinator opened 2 years ago

Alwinator commented 2 years ago

You caprover action worked great for month, but for one week it does not work with the following exception:

Preparing deployment to CapRover...

**** Warning ****
No captain-definition was found in main directory: falling back to Dockerfile.

Ensuring authentication...
Cannot find hash of last commit on branch "main".
Alwinator commented 2 years ago

I think it could be fixed by rebuilding because then npm installs the latest Caprover CLI which fixed the bug.

jfm-wcs commented 2 years ago

Hi, got exactly the same issue. Deployment to caprover fails. Some npm warning from previous step Build AlexxNB/caprover-action@v1 could they be involved ?

Alwinator commented 2 years ago

I used a workaround, it might not be as fast, but it always uses the latest version. Replace the action:

- name: Caprover Deploy
  uses: AlexxNB/caprover-action@v1
  with:
     server: 'https://example.com'
     password: '${{ secrets.CAPROVER_PASSWORD }}'
     appname: 'myapp'
     branch: 'main'

With the following code that installs the Caprover CLI in the pipeline and deploys your app.

- name: Set up npm
  uses: actions/setup-node@v2
  with:
     node-version: '14'

- name: Install caprover
  run: npm install -g caprover

- name: Caprover Deploy
  run: caprover deploy -h 'https://example.com' -p '${{ secrets.CAPROVER_PASSWORD }}' -b 'main' -a 'myapp'
jfm-wcs commented 2 years ago

Works fine! Not that slow, thanks!

Alwinator commented 2 years ago

After a little investigation, the bug is caused by this line. The problem is that the Github checkout action only pulls the latest hash which causes an issue with git rev-list. It can be fixed by adding fetch-depth: 0, see git-rev-list-not-working-inside-github-action. For some reason, it also works when using Ubuntu instead of Alpine, but that makes it even slower.

 uses: actions/checkout@v2
 with:
   fetch-depth: 0

However,

I realized after benchmarking that installing the Caprover CLI in the pipeline as mentioned in my comment before is a much better solution than using this action because it only takes 13 seconds. This action takes 28 seconds and it is already based on alpine, so it cannot be improved a lot.

13 second solution (without action):

- name: Set up npm
  uses: actions/setup-node@v2
  with:
     node-version: '14'

- name: Install caprover
  run: npm install -g caprover

- name: Caprover Deploy
  run: caprover deploy -h 'https://example.com' -p '${{ secrets.CAPROVER_PASSWORD }}' -b 'main' -a 'myapp'
Teemu commented 1 year ago

Thanks @Alwinator !

kristijanPetr commented 6 months ago

After two days of trial and error and trying above methods, I couldn't get to work. Finnaly found solution, actually you would need to checkout to the branch that is referenced.

 - name: Checkout to branch
        run: |
          git fetch origin ${{ github.head_ref }}
          git checkout ${{ github.head_ref }}
anhitvn commented 5 months ago

econd solution (without action):

- name: Set up npm
  uses: actions/setup-node@v2
  with:
     node-version: '14'

Thank you for your instructions, I followed it and it worked. Really thanks