Get latest pigpio release tag #1177
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: Get latest pigpio release tag | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
# Run when file is edited | |
- .github/workflows/get-last-release-pigpio.yml | |
schedule: | |
- cron: '0 10 * * *' | |
workflow_dispatch: | |
env: | |
# Repo info here: | |
REPO_OWNER: joan2937 | |
REPO_TITLE: pigpio | |
jobs: | |
get-pigpio-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out | |
uses: actions/checkout@v4 | |
with: | |
# Use PAT so allow this action to trigger a new action | |
token: ${{ secrets.PAT }} | |
- name: Fetch latest release tag | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Use github API to get latest release (tag_name) | |
RELEASE_TAG=$( curl -sL https://api.github.com/repos/$REPO_OWNER/$REPO_TITLE/releases/latest --header "Authorization: Bearer $GH_TOKEN" | jq -r ".tag_name" ) | |
if [ -z "$RELEASE_TAG" ] || [ "$RELEASE_TAG" = "null" ]; then | |
echo "Error in found release tag=$RELEASE_TAG" | |
RELEASE_TAG=$( curl -L https://api.github.com/repos/$REPO_OWNER/$REPO_TITLE/releases/latest) | |
echo "Curl content" | |
echo "$RELEASE_TAG" | |
RELEASE_TAG=$(echo $RELEASE_TAG | jq -r ".tag_name" ) | |
fi | |
# Print the found release tag | |
echo "Release tag=$RELEASE_TAG" | |
if [ -z "$RELEASE_TAG" ] || [ "$RELEASE_TAG" = "null" ]; then | |
echo "Content of RELEASE_TAG is null. Cant continue." | |
exit 1 | |
fi | |
# Save the release as github environment variable to be used at later steps | |
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV | |
# Save the found release to a file in folder(folder must be there before) | |
echo "$RELEASE_TAG" > "release-versions/$REPO_TITLE-latest.txt" | |
# Content of file | |
cat "release-versions/$REPO_TITLE-latest.txt" | |
- name: Push changes | |
# This needs actions/checkout to be able push to repo | |
run: | | |
git config user.name "bot_${{ github.event_name }}" | |
git config user.email "bot_${{ github.event_name }}@users.noreply.github.com" | |
# Add all files to commit in current and sub folders | |
git add . | |
# Check if something changed and then commit | |
git diff --quiet HEAD || git commit -m "Auto. A ${{ github.event_name }} added this" | |
git push |