Mới gặp trường hợp có nhu cầu dùng git để tải vài file về và lưu vào git. Trigger bằng cách gọi github api.
Tạo 1 github action như sau
name: File Loader
on:
  repository_dispatch:
    types: download_file
permissions:
  contents: write
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Check out repository
      uses: actions/checkout@v3
          
    - name: Load files from URLs
      run: |
        wget "<YOUR_URLS_LINKs>"  -O  list.txt
        wget -i list.txt
    - name: Commit and push changes
      run: |
        git config --local user.email "[email protected]"
        git config --local user.name "GitHub Action"
        git add .
        git commit -m "Update file from URL"
        git pushThay biến YOUR_URLS_LINKs bằng 1 link nào đó chưa toàn bộ url bạn muốn push lên git (ví dụ http://abcxyz.com/list.txt).
Note: Tôi không parse từ json gửi lên vì tôi không muốn bất kỳ ai nắm key github cũng được tác động vào phần này, và nếu gửi cả dữ liệu lên có vẻ không ổn lắm về bảo mật.
Gọi action này như sau:
curl --location 'https://api.github.com/repos/<USERNAME>/<REPO_NAME>/dispatches' \
--header 'Accept: application/vnd.github+json' \
--header 'Authorization: Bearer <GITHUB_ACCESS_TOKEN>' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
--header 'Content-Type: application/json' \
--data '{
    "event_type": "download_file",
    "client_payload": {}
}'
 
                                        
                
                 
  
  
 