【问题标题】:Use Github Actions to make API get request and save data to repo使用 Github Actions 发出 API 获取请求并将数据保存到 repo
【发布时间】:2020-08-31 06:33:49
【问题描述】:

我想设置一个 GitHub 操作工作流:

  1. 向另一个站点(GitHub 外部)发出 API 请求,该站点返回 JSON。
  2. 将该 JSON 添加(提交)到我的存储库中

我有一个如下所示的操作。它似乎运行正确,日志甚至输出文件已保存。但是,该文件从未出现在我的仓库中的任何位置。

我以前从未设置过动作,所以我对它们周围的一些术语也很陌生。

关于如何执行此操作或工作的任何提示或想法,或替代方法?

name: Refresh Feed
on: [push]
jobs:
  refresh-feed:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false
  
      - name: Fetch API Data
        uses: JamesIves/fetch-api-data-action@1.0.15
        with:
          ENDPOINT: https://www.loc.gov/maps/?fa=location:cyprus&fo=json&at=results
          RETRY: true

【问题讨论】:

    标签: github github-actions building-github-actions


    【解决方案1】:

    我的意思是从 repo 的自述文件看来,您只需要使用 github 令牌运行此操作。我刚刚运行了 Fetch API Data 操作,并且能够看到通过在操作后的一个步骤上运行 ls 创建的新目录。

    How to get github token

    然后你需要创建一个秘密并添加 env ACCESS_TOKEN

    How to create secrets in repo

    要运行的动作

    name: Refresh Feed
    on: 
      schedule:
        - cron: 10 15 * * 0-6
    jobs:
      refresh-feed:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout ?️
            uses: actions/checkout@v2
            with:
              persist-credentials: false
    
          - name: Fetch API Data ?
            uses: JamesIves/fetch-api-data-action@releases/v1
            with:
              ENDPOINT: https://www.loc.gov/maps/?fa=location:cyprus&fo=json&at=results
              retry: true
          - name: Build and Deploy ?
            uses: JamesIves/github-pages-deploy-action@releases/v3
            with:
              ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
              BRANCH: master # Pushes the updates to the master branch.
              FOLDER: fetch-api-data-action # The location of the data.json file saved by the Fetch API Data action.
              TARGET_FOLDER: data # Saves the data into the 'data' directory on the master branch.
    

    【讨论】:

      猜你喜欢
      • 2019-12-21
      • 2022-10-22
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      相关资源
      最近更新 更多