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?
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 'your-email@users.noreply.github.com'
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.