对外部回购更新(推送)触发 GitHub 操作
Trigger a GitHub Action on a foreign repo update (push)
我正在尝试镜像一个我不拥有的 public 存储库,更重要的是镜像他们的推送(以触发另一个操作)。
目前,我看到的同步操作似乎是将一个存储库复制粘贴到我拥有的一个存储库中,但该存储库的推送不会触发操作。
有办法做到这一点吗?
我不认识外国回购的所有者。我知道所有者可以发送调度事件,但我想要一个不依赖于某人善意的解决方案。
基本上,我希望发生这种情况:
我的仓库每小时与一个外国仓库同步,如果最近一小时有更新,则会触发另一个操作。
有办法吗?
对于有同样问题的人,我通过 cron 计划找到了一个方法:
- 在您的存储库中创建一个空文本文件
- 检查原始仓库的提交 ID
- 如果该 id 与文本文件中的不同,则触发同步操作(以及可选的任何其他操作),然后将提交 id 添加到一个小文本文件中
- 否则什么都不做
- 按 cron 计划从 2 开始重复
外部仓库的更新将在 cron 计划上触发。
这不是我想要的,但足够接近了。
编辑:
这是来自 my repo 的完整 .yml 文件示例,已进行注释以使其更短
name: Sync+build+push TTRSS
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
get_commits:
runs-on: ubuntu-latest
outputs:
LOCAL: ${{ steps.commits.outputs.SETLOCAL }}
REMOTE: ${{ steps.commits.outputs.SETREMOTE }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker'
- name: set local and remote latest commit as environment variables
id: commits
run: |
echo "::set-output name=SETREMOTE::$(git ls-remote https://git.tt-rss.org/fox/ttrss-docker-compose.git HEAD | awk '{ print }')"
echo "::set-output name=SETLOCAL::$(cat last_sync_with_original_repo_commit_id)"
repo_sync:
needs: [get_commits]
runs-on: ubuntu-latest
if: needs.get_commits.outputs.LOCAL != needs.get_commits.outputs.REMOTE
steps:
- name: repo-sync
uses: wei/git-sync@v3
with:
source_repo: "https://git.tt-rss.org/fox/ttrss-docker-compose.git"
source_branch: "master"
destination_repo: "git@github.com:schklom/Mirror-workflows.git"
destination_branch: "TTRSS-docker"
ssh_private_key: ${{ secrets.GITSYNCACTION }}
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker'
- name: get most recent commit id on original repo, for next comparison on sync
run: git ls-remote https://git.tt-rss.org/fox/ttrss-docker-compose.git HEAD | awk '{ print }' > last_sync_with_original_repo_commit_id
- name: Commit and push the change
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Add last_sync_with_original_repo_commit_id
build_push:
needs: [repo_sync]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker'
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push TTRSS app
uses: docker/build-push-action@v2
with:
context: ./app
file: ./app/Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
pull: true
push: true
tags: |
schklom/ttrss-app:latest
- name: Build and push TTRSS web-nginx
uses: docker/build-push-action@v2
with:
context: ./web-nginx
file: ./web-nginx/Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
pull: true
push: true
tags: |
schklom/ttrss-web-nginx:latest
build_push_filelogging:
needs: [build_push]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker-with-filelogging'
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push TTRSS app (with file logging)
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
pull: true
push: true
tags: |
schklom/ttrss-app:with-filelogging-latest
我正在尝试镜像一个我不拥有的 public 存储库,更重要的是镜像他们的推送(以触发另一个操作)。
目前,我看到的同步操作似乎是将一个存储库复制粘贴到我拥有的一个存储库中,但该存储库的推送不会触发操作。 有办法做到这一点吗?
我不认识外国回购的所有者。我知道所有者可以发送调度事件,但我想要一个不依赖于某人善意的解决方案。
基本上,我希望发生这种情况: 我的仓库每小时与一个外国仓库同步,如果最近一小时有更新,则会触发另一个操作。
有办法吗?
对于有同样问题的人,我通过 cron 计划找到了一个方法:
- 在您的存储库中创建一个空文本文件
- 检查原始仓库的提交 ID
- 如果该 id 与文本文件中的不同,则触发同步操作(以及可选的任何其他操作),然后将提交 id 添加到一个小文本文件中
- 否则什么都不做
- 按 cron 计划从 2 开始重复
外部仓库的更新将在 cron 计划上触发。
这不是我想要的,但足够接近了。
编辑: 这是来自 my repo 的完整 .yml 文件示例,已进行注释以使其更短
name: Sync+build+push TTRSS
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
get_commits:
runs-on: ubuntu-latest
outputs:
LOCAL: ${{ steps.commits.outputs.SETLOCAL }}
REMOTE: ${{ steps.commits.outputs.SETREMOTE }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker'
- name: set local and remote latest commit as environment variables
id: commits
run: |
echo "::set-output name=SETREMOTE::$(git ls-remote https://git.tt-rss.org/fox/ttrss-docker-compose.git HEAD | awk '{ print }')"
echo "::set-output name=SETLOCAL::$(cat last_sync_with_original_repo_commit_id)"
repo_sync:
needs: [get_commits]
runs-on: ubuntu-latest
if: needs.get_commits.outputs.LOCAL != needs.get_commits.outputs.REMOTE
steps:
- name: repo-sync
uses: wei/git-sync@v3
with:
source_repo: "https://git.tt-rss.org/fox/ttrss-docker-compose.git"
source_branch: "master"
destination_repo: "git@github.com:schklom/Mirror-workflows.git"
destination_branch: "TTRSS-docker"
ssh_private_key: ${{ secrets.GITSYNCACTION }}
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker'
- name: get most recent commit id on original repo, for next comparison on sync
run: git ls-remote https://git.tt-rss.org/fox/ttrss-docker-compose.git HEAD | awk '{ print }' > last_sync_with_original_repo_commit_id
- name: Commit and push the change
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Add last_sync_with_original_repo_commit_id
build_push:
needs: [repo_sync]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker'
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push TTRSS app
uses: docker/build-push-action@v2
with:
context: ./app
file: ./app/Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
pull: true
push: true
tags: |
schklom/ttrss-app:latest
- name: Build and push TTRSS web-nginx
uses: docker/build-push-action@v2
with:
context: ./web-nginx
file: ./web-nginx/Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
pull: true
push: true
tags: |
schklom/ttrss-web-nginx:latest
build_push_filelogging:
needs: [build_push]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'TTRSS-docker-with-filelogging'
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push TTRSS app (with file logging)
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
pull: true
push: true
tags: |
schklom/ttrss-app:with-filelogging-latest