Check for New Releases #159
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for New Releases | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Runs every hour | |
workflow_dispatch: | |
jobs: | |
check_and_release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Check for new Photon release | |
id: check_release | |
run: | | |
latest_release=$(curl -s https://github.com/komoot/photon/releases.atom | grep '<title>' | sed -n '2p' | sed -E 's/.*Release ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') | |
echo "latest_release=${latest_release}" >> "$GITHUB_ENV" | |
- name: Get last processed release | |
id: get_last_release | |
run: | | |
echo "last_release=$(cat .last_release)" >> "$GITHUB_ENV" | |
continue-on-error: true | |
- name: Create Release | |
if: env.latest_release != env.last_release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ env.latest_release }} | |
name: Release ${{ env.latest_release }} | |
body: | | |
New Photon release: ${{ env.latest_release }} | |
This is an automated release created by the GitHub Actions workflow. | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.MY_PAT_TOKEN }} | |
- name: Update last release file | |
if: env.latest_release != env.last_release | |
run: | | |
echo "${latest_release}" > .last_release | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add .last_release | |
git commit -m "Update last processed release to ${latest_release}" | |
git push --force | |
- name: Trigger build workflow | |
if: env.latest_release != env.last_release | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.MY_PAT_TOKEN }} | |
script: | | |
github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'build-and-push.yml', | |
ref: 'main', | |
inputs: { | |
release_tag: '${{ env.latest_release }}' | |
} | |
}) |