Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a GitHub Action when another repository creates a new release

I'm trying to build a GitHub workflow that will be triggered when another repository creates a new release.

In the documentation, there is the paragraph: on.event_name.types where event_name will be release.

The question is: Is there any way to refer to the release event of another repository?

like image 998
pierDipi Avatar asked Oct 19 '19 15:10

pierDipi


People also ask

How do I trigger a workflow from another workflow in GitHub Actions?

If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of GITHUB_TOKEN to trigger events that require a token. You'll need to create a personal access token and store it as a secret.

Can you manually trigger a GitHub Action?

Earlier this week, GitHub announced a new feature which allows developers to trigger workflows manually from within the “Actions” tab.


1 Answers

Is there any way to refer to the release event of another repository?

Fairly sure this feature does not exist.

If you have have access to the repository creating the release then you could call a webhook event to trigger an on: repository_dispatch workflow to run in another repository. repository-dispatch action can help in this case.

If you don't have access to the repository creating the release (which I assume is the case here) then this would be my suggestion. First, create the following workflow that periodically checks the release version tag of the repository you want to track. If it differs from the release version you currently have saved in your repository then the new version will be committed.

Note that you must prepare the destination file first (e.g. release-versions/swagger-ui-latest.txt) for the the modified files check to work. Further, you must use a repo scoped token instead of the default GITHUB_TOKEN. For more detail about that see Push to origin from GitHub action

name: Get latest release version
on:
  schedule:
    - cron:  '0 10 * * *'
jobs:
  get-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.REPO_SCOPED_TOKEN }}
      - name: Fetch release version
        run: |
          curl -sL https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | \
          jq -r ".tag_name" > release-versions/swagger-ui-latest.txt
      - name: Check for modified files
        id: git-check
        run: echo ::set-output name=modified::$([ -z "`git status --porcelain`" ] && echo "false" || echo "true")
      - name: Commit latest release version
        if: steps.git-check.outputs.modified == 'true'
        run: |
          git config --global user.name 'Your Name'
          git config --global user.email '[email protected]'
          git commit -am "New release version"
          git push

Then you can create a second workflow that only runs when it sees any changes to the directory release-versions.

on:
  push:
    paths:
      - 'release-versions/*'

In this workflow you can use the saved version to fetch the assets you need and do whatever processing you need to.

Here is a similar example that raises a pull request instead of committing immediately.

like image 99
peterevans Avatar answered Oct 09 '22 18:10

peterevans