如何从github操作触发推送到远程服务器的推动?

发布于 2025-02-08 20:24:41 字数 2388 浏览 3 评论 0原文

本地设置了这个遥控器

$ git remote -v
dev [email protected]:/home/myuser/maps.git (fetch)
dev [email protected]:/home/myuser/maps.git (push)

我从远程存储库中的

# The production directory
TARGET="/var/www/html"

# A temporary directory for deployment
TEMP="/home/myuser/deploy-folder"

# The Git repo
REPO="/home/myuser/maps.git"

# Deploy the content to the temporary directory
mkdir -p $TEMP
#git --work-tree=$TEMP --git-dir=$REPO checkout -f
cd $TEMP
git pull
...

,我有一个挂钩,〜/maps.git/hooks/tost-receive,我想做的就是每当PR合并到特定分支(身份验证)时,我想从GitHub操作触发“ Git Push Dev”代码将其推向远程服务器。不太确定如何填写我的github动作。我有这个

name: "Build Dev & Release"
on:
  push:
    paths:
      - "**"
      - ".github/workflows/my-github-action.yml"
    branches:
      - authentication
jobs:
  pusht-to-dev-server:
    ???

,但不太确定如何实施“推向dev-server”动作。

编辑:回答给出的答案,我创建了此文件

$ cat .github/workflows/directory-dev.yml 
name: "Chicommons Maps Dev: Build & Release"
on:
  push:
    paths:
      - "**"
      - ".github/workflows/directory-dev.yml"
    branches:
      - authentication 

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
        fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_url: dev.myremote.com:/home/myusername/maps.git
        github_token: ${{ secrets.DEPLOY }}
        branch: ${{ github.ref }}

,然后创建了此环境,秘密

”

但是当我推到分支(自动化)时,我会得到此错误

Run ad-m/github-push-action@master 

Push to branch refs/heads/authentication 

Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".

I have this remote set up from my local

$ git remote -v
dev [email protected]:/home/myuser/maps.git (fetch)
dev [email protected]:/home/myuser/maps.git (push)

In my remote repo, I have a hook, ~/maps.git/hooks/post-receive, with

# The production directory
TARGET="/var/www/html"

# A temporary directory for deployment
TEMP="/home/myuser/deploy-folder"

# The Git repo
REPO="/home/myuser/maps.git"

# Deploy the content to the temporary directory
mkdir -p $TEMP
#git --work-tree=$TEMP --git-dir=$REPO checkout -f
cd $TEMP
git pull
...

What I would like to do is whenever a PR merges into a particular branch (authentication), I would like to trigger a "git push dev" code push to the remote server from a GitHub action. Not quite sure how to fill in my GitHub action. I have this

name: "Build Dev & Release"
on:
  push:
    paths:
      - "**"
      - ".github/workflows/my-github-action.yml"
    branches:
      - authentication
jobs:
  pusht-to-dev-server:
    ???

but not quite sure how to implement the "push-to-dev-server" action.

Edit: In response to the answer given, I created this file

$ cat .github/workflows/directory-dev.yml 
name: "Chicommons Maps Dev: Build & Release"
on:
  push:
    paths:
      - "**"
      - ".github/workflows/directory-dev.yml"
    branches:
      - authentication 

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
        fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_url: dev.myremote.com:/home/myusername/maps.git
        github_token: ${{ secrets.DEPLOY }}
        branch: ${{ github.ref }}

and I created this environment encrypted secret

enter image description here

but when I push to my branch (autnentication), I get this error

Run ad-m/github-push-action@master 

Push to branch refs/heads/authentication 

Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2025-02-15 20:24:41

请注意,这将假设mydomain.remote是互联网的(而不是仅在本地,在DMZ后面)。

这意味着GITHUB服务器(执行GitHub操作/工作流)必须能够查看并联系myDomain.Remote

您可以使用 github-push-action最初是为了推到GitHub存储库,但是您可以更改以包括自己的域服务器。

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
        fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_url: mydomain.remote
        github_token: ${{ secrets.YOURDOMAIN_TOKEN }}
        branch: ${{ github.ref }}

Note that this would assume mydomain.remote is internet-facing (as opposed to on-premise only, behind a DMZ).

That means GitHub servers (where the GitHub action/workflow is executed) must be able to see and contact mydomain.remote.

You can the use the github-push-action, initially made to push to a GitHub repository, but that you can change to include your own domain server.

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
        fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_url: mydomain.remote
        github_token: ${{ secrets.YOURDOMAIN_TOKEN }}
        branch: ${{ github.ref }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文