使用github操作来concat json文件

发布于 2025-02-07 04:18:35 字数 291 浏览 1 评论 0原文

我有一个包含JSON文件的目录,我想使用github操作在存储库中创建一个新文件,其中包含所有这些JSON文件的数组。 例如,目录< my-repo>/configurations包含文件a.jsonb.json,我想创建一个称为configs.json的新文件包含[< a.json content> ,,< b.json content>]。 创建必须动态完成。 有什么建议吗?

I have a directory containing json files, and i want to use github actions to create a new file in the repository, that contains an array of all those json files.
for example, the directory <my-repo>/configurations contain the files a.json, b.json, I want to create a new file called configs.json contains [<a.json content>,<b.json content>].
The creation must be done dynamically.
Any suggestions?

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

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

发布评论

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

评论(1

征﹌骨岁月お 2025-02-14 04:18:35

坐在\ configs目录下的配置文件的解决方案:

name: build unified config file
on: [push]
jobs:
  build_file:
    name: build unified config file
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - name: Run script
        uses: jannekem/run-python-script-action@v1
        with:
          script: |
            import os, json, shutil
            with open("unified.json", "r+") as t:
              t.truncate(0)
              t.write('[')
              for filename in os.scandir('configs'):
                print(filename)
                with open(filename, "r") as f:
                  content = f.read()
                  t.write(content)
                  t.write(',')
              t.write(']')
            barak = open("unified.json", "r+")
            contentb = barak.read()
            print(contentb)
      - name: push file to main
        uses: EndBug/add-and-commit@v9
        with:
          add: 'unified.json'
          committer_name: Committer Name
          committer_email: [email protected]
          default_author: github_actor
          message: 'Update unified config file'
          push: true

solution for config files sitting under \configs directory:

name: build unified config file
on: [push]
jobs:
  build_file:
    name: build unified config file
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - name: Run script
        uses: jannekem/run-python-script-action@v1
        with:
          script: |
            import os, json, shutil
            with open("unified.json", "r+") as t:
              t.truncate(0)
              t.write('[')
              for filename in os.scandir('configs'):
                print(filename)
                with open(filename, "r") as f:
                  content = f.read()
                  t.write(content)
                  t.write(',')
              t.write(']')
            barak = open("unified.json", "r+")
            contentb = barak.read()
            print(contentb)
      - name: push file to main
        uses: EndBug/add-and-commit@v9
        with:
          add: 'unified.json'
          committer_name: Committer Name
          committer_email: [email protected]
          default_author: github_actor
          message: 'Update unified config file'
          push: true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文