Update a different repository using a github action

2 min read

When building an application we might like to update a different repository to update the app's versions number. For example, if we build a docker containter using a github action we might want to update the tag on the helm repository. This is by default restricted: a github action only has access to it's own repository but we can create a PAT to workaround this problem

So, first we will have create a PAT. To do so we will have to login into gtihub, and search for Personal access tokens under Settings/Developer settings. We will have to create a new PAT and give it access to the repos to be able to push changes to them

With this toke we will have to create a new secret on the repository we are going to run the github action (the first repo). You can create the New repository secret under your repo Settings/Secrets. We can choose whatever name we'd like, on this example I'm going to use PAT_REPO_UPDATE to identify what's for

The last thing we need to do is to add the actions on the github action to:

  • Checkout the repository we want to update (the other repo)
  • Update the files we'd like to change
  • Commit and push the changes

We'll need to update it using the following steps:

      - name: Checkout helm chart
        uses: actions/checkout@v2
          repository: jordiprats/helm-pet2cattle
          token: ${{ secrets.PAT_REPO_UPDATE }}
          path: ./helm-pet2cattle

      - name: Update chart.yaml
        run: |
          sed 's/appVersion: "[^"]*"/appVersion: "${{ steps.vars.outputs.tag }}"/' -i ./helm-pet2cattle/Chart.yaml

      - name: Push helm changes
        uses: EndBug/add-and-commit@v7
          cwd: ./helm-pet2cattle
          message: 'update app version'
          branch: master

You can find a full example on the repo flask-pet2cattle, when the docker image is built it updates it's helm chart

Posted on 29/10/2021