str
str

Reputation: 45039

GitHub pipeline/CI to generate files and push them back to the repository

I maintain a public repository on GitHub where changes are only made to a single YAML file. I'm looking for a solution to process that file on every push and generate files based on it. Essentially, a pipeline or CI should parse the file and create many different markdown files. These files (or more specifically, the changes to these files) should then be pushed back to the repository.

Requirements:

There are Travis providers for GitHub Pages and GitHub Releases. But both have limitations that make them unsuitable for my requirements.

Using what tool/CI/pipeline can I achieve that on GitHub? I would prefer a service over a self-hosted CI.

Upvotes: 8

Views: 2312

Answers (2)

NFSpeedy
NFSpeedy

Reputation: 171

You can do this now with the free GitHub Actions option for the repositories. You need to put this step into your YAML file.

    - name: Commit back to GitHub
      run: |
        git config --global user.name "github-actiuons[bot]"
        git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

        git add -A
        git commit -m "Updating some file"
        git push

There are some items in the marketplace, but they didn't work for me.

The email of the bot is based on this thread:

https://github.community/t/github-actions-bot-email-address/17204

  • Update the commit message.
  • Be careful with the folder paths if you decide to push a specific file in a folder.

Upvotes: 0

M. F.
M. F.

Reputation: 1744

Assuming that you already have the program/script to parse the YAML file and to generate the Markdown files, I can give you some insights on how I would do this from Jenkins CI. While I draw my experience from running my own instance, there are also hosted options such as CloudBees that you can explore.

  1. Create a new Jenkins Freestyle project.
  2. Under the Source Code Management section, configure your GitHub project coordinates.
  3. Under Build Triggers section, activate the 'Build when a change is pushed to GitHub' option. That would launch the CI job at the moment you push a new version of the YAML file into the repository.
  4. Under the build section, add an Execute shell build step.
  5. In the shell step, launch the program or script that processes the YAML file/generates the .md files. End the script by adding the git add ., git commit -m "message", git pull and git push commands (assumes git is in the path).
  6. Enable the new job to make it active in Jenkins.

Upvotes: 4

Related Questions