[英]Call external Rest api when a file is added or updated to a Github repository
So, I have a Github repository where some files will be added or updated manually or through a merge from feature branch to main branch.所以,我有一个Github 存储库,其中一些文件将被手动添加或更新,或者通过从功能分支到主分支的合并。 I want to know how can I call another external microservice Rest api endpoint (.Net 6.0 endpoint), whenever files are added/updated to this Github repository or merged from feature branch to main branch?
我想知道每当将文件添加/更新到此 Github 存储库或从功能分支合并到主分支时,如何调用另一个外部微服务 Rest api 端点(.Net 6.0 端点)?
These are custom files (consider.txt files) which also need to be sent to the external microservice api endpoint so that this endpoint can process received files and save the data to DB.这些是自定义文件(consider.txt 文件) ,它们也需要发送到外部微服务 api 端点,以便该端点可以处理接收到的文件并将数据保存到数据库。
Can someone pls help in solution to above question so that I can push the modified/added files from Github repo to call Rest api endpoint?有人可以帮助解决上述问题,以便我可以从 Github repo 推送修改/添加的文件来调用 Rest api 端点吗?
I looked into this link for solution but could not understand it?我查看了此链接以寻求解决方案,但无法理解? Can I use Github actions for solution to this problem (and how?) or is there any alternate solution?
我可以使用 Github 操作来解决这个问题(以及如何?)或者是否有任何替代解决方案? Any link to solution will also help... Thanks..
解决方案的任何链接也将有所帮助...谢谢..
A possible workflow in this case:这种情况下可能的工作流程:
Example:例子:
name: 'Call REST API when a file is pushed'
on:
push:
paths:
- '*.txt' # match '*.txt' files (created or updated)
branches: [ main ] # match specific branch
jobs:
prepare-files:
runs-on: ubuntu-latest
outputs:
matrix-added: ${{ steps.file-changes.outputs.files_added }}
matrix-modified: ${{ steps.file-changes.outputs.files_modified }}
steps:
- id: file-changes
uses: trilom/file-changes-action@v1.2.4
post-files-added:
needs: prepare-files
runs-on: ubuntu-latest
strategy:
matrix:
file: ${{ fromJSON(needs.prepare-files.outputs.matrix-added) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Echo file
run: |
echo ${{ matrix.file }} # to test if the correct file was passed
- name: Make an API call
uses: fjogeleit/http-request-action@v1
with:
url: 'https://postman-echo.com/post'
method: 'POST'
file: "${{ github.workspace }}/${{ matrix.file }}"
# post-files-modified:
# ...
Additional references:其他参考资料:
Also, there is another possible approach - you can set up a GitHub webhook for your repo that will trigger an API endpoint on the push event.此外,还有另一种可能的方法——您可以为您的存储库设置一个 GitHub webhook,它将在推送事件上触发 API 端点。 For more details, see Automatically copy pushed files from one GitHub repository to another (this example is about copying files to another repository, but the same approach could be used in your case)
有关详细信息,请参阅自动将推送的文件从一个 GitHub 存储库复制到另一个(此示例是关于将文件复制到另一个存储库,但您的情况可以使用相同的方法)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.