milanmk / actions-file-deployer

Composite GitHub Action (Linux runner) for deploying repository content to remote server. Fast and customizable deployment with proxy support. Deploy only changed files or do full sync/mirror of repository content.
The Unlicense
62 stars 14 forks source link

Delta Syning combined with push action not working #38

Open AlexMi-Ha opened 2 months ago

AlexMi-Ha commented 2 months ago

My Workflow starts when I push to main, builds the project and pushes the artifact from the dest folder to the gh-pages branch. Now I want to sync the gh-pages branch to my sftp server. This does not work, as the sftp action gets the changes from the main branch not from the gh-pages branch.

When using the delta mode, the script still looks at the latest commit in the main branch not in the gh-pages branch, because the {{github.sha}} variable points to main, as main triggered the workflow.

The action should use git cli to determine the latest commit and not rely on the github context.

Example workflow:

on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    name: Build and Push
    steps:
      - name: git-checkout
        uses: actions/checkout@v2 
      - name: Build
        run: |
          build.sh
      - name: Push
        uses: s0/git-publish-subdir-action@develop
        env:
          REPO: self
          BRANCH: gh-pages
          FOLDER: dest/
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          MESSAGE: "Build: ({sha}) {msg}"

  deploy:
    runs-on: ubuntu-latest
    name: Deploy to FTP
    needs: build
    steps:
      - name: git-checkout
        uses: actions/checkout@v2 
        with:
          fetch-depth: 0
          ref: gh-pages

      - name: Sync to FTP server
        uses: milanmk/actions-file-deployer@master
        with:
          remote-protocol: sftp
          remote-host: ${{ secrets.FTP_HOST }}
          remote-user: ${{ secrets.FTP_USER }}
          remote-password: ${{ secrets.FTP_PASSWORD }}
          remote-path: /prod
          remote-port: ${{ secrets.FTP_PORT }}

Already tried putting the sftp action into another workflow which triggers on push to gh-pages, but a push by the GTIHUB_TOKEN credentials does not trigger workflows - i would have to use a PAT :(

With full sync, everything works, because no commit history is looked at and the {{ github.sha }} is not referenced