2

I am trying to pull change from origin using GitHub Actions.

I have a workflow in yml file set up like below. I have a runner (self-hosted) set up on my apache server so that it will run git pull when code is pushed to xxx branch. I confirmed that it was running and connected to GitHub. When I commit change and merge it to xxx branch, workflow runs without error. However, git pull says 'Already up to date' even though there is change.

How do I properly pull using GitHub actions?

# This is a basic workflow to help you get started with Actions

name: Test

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ xxx ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: self-hosted

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # pull the change for deploy-test
      - name: Pull the change from server
        env:
          USERNAME: ${{ secrets.USERNAME }}
          TOKEN: ${{ secrets.TOKEN }}
        run: | 
          git pull origin xxx --rebase
          echo $USERNAME
          echo $TOKEN

When I run git pull manually in the server, it pulls the change like below.

remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 18 (delta 9), reused 10 (delta 4), pack-reused 0
Unpacking objects: 100% (18/18), 2.87 KiB | 978.00 KiB/s, done.
From https://github.com/my-username/my-directory
 * branch            xxx -> FETCH_HEAD
   myhash..myhash  xxx -> origin/xxx
Updating a22125c..a2981f2
Fast-forward
 .github/workflows/test.yml | 10 ++++++++++
 1 file changed, 10 insertions(+)

But github actions says this

git pull origin xxx --rebase
https://github.com/***/my-directory
 * branch            xxx -> FETCH_HEAD
Already up to date.
***
***
  • Doesn't the `actions/checkout` already perform this operation for you? – GuiFalourd Mar 10 '22 at 17:37
  • @GuiFalourd thank you for your comment. I just checked it now and it doesn't perform this operation by itself. when I run git pull origin xxx --rebase in the actual server manually, it pulls change. But github actions doesn't. It just says 'Already up to date'. – user18431308 Mar 10 '22 at 17:49
  • Did you solve your issue? – angelzzz Feb 26 '23 at 18:23

1 Answers1

0

- uses: actions/checkout@v2 is checking out repository in its latest stage for you - so if you pull just after that it will correctly confirm that everything is up to date and that there's nothing more to pull.

shim
  • 9,289
  • 12
  • 69
  • 108
Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
  • Thank you for your comment. I kinda understand what you are saying but if I pushed the code and merged the branch to `xxx`. Shouldn't there be new change to pull? So for instance I pushed the code to dev and merged into this `xxx` branch. Shouldn't github actions identify the change and pull it since there is a change in the latest stage? – user18431308 Mar 10 '22 at 18:30
  • It will checkout the different branch depending on trigger point by default. For PRs it will checkout ref/pr/merge points. – Grzegorz Krukowski Mar 10 '22 at 22:40