2

I have self-hosted runner with the below yml file. Everything runs successfully, but when I ssh into the server and cd to the application directory, the code is one commit behind the main branch. If I run git pull, it pulls the latest commit. Here is my configuration file:

name: Build and Deploy
on: push
jobs:
  Deploy-on-local-runner:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v3
      - name: run npm ci
        run: npm ci
      - name: npm run build
        run: npm run build

I made the change that VonC recommended and it does not appear to have any change in the code. I updated the yml file and changed a test.txt file, and the action ran successfully but did not update the files on disk on the server. When I SSH'd in to the box and ran git pull this is what I received in response:

kevin@machine:~/projects/project$ git pull
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 6 (delta 2), reused 6 (delta 2), pack-reused 0
Unpacking objects: 100% (6/6), 449 bytes | 64.00 KiB/s, done.
From github.com:user/repo
   bc759e9..1e4b98e  main       -> origin/main
Updating bc759e9..1e4b98e
Fast-forward
 .github/workflows/deploy.yml | 3 +++
 test.txt                     | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
Kevin
  • 895
  • 2
  • 10
  • 21

1 Answers1

0

As noted in actions/checkout issues

You can use the ref attribute to point to a specific branch.
This way subsequent jobs always pull the latest code from that branch, and not from the revision that started the workflow.

If the problem is that it (the actions/checkout) does not fetch the full commit history, add a fetch-depth: 0

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: main
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi VonC - I've just attempted your change, and it did not update my test.txt file. When I manually ran ```git pull``` it updated correctly (as noted in my question). – Kevin Sep 15 '22 at 21:19
  • 1
    @Kevin OK, it was worth a shot. Not sure why the latest from that branch is not pulled though. – VonC Sep 15 '22 at 21:35