Update AirSane Release #34
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: Update AirSane Release | |
on: | |
workflow_dispatch: # Allows manual trigger | |
schedule: | |
- cron: "0 3 * * 5" # 3 AM UTC every Friday | |
jobs: | |
check_release_exists: | |
name: Check whether upstream has any changes | |
runs-on: ubuntu-latest | |
outputs: | |
release_exists: ${{ steps.check_release.outputs.exists }} | |
tag: ${{ steps.fetch_release.outputs.tag }} | |
release_date: ${{ steps.fetch_release.outputs.release_date }} | |
release_title: ${{ steps.fetch_release.outputs.release_title }} | |
release_url: ${{ steps.fetch_release.outputs.release_url }} | |
commit_hash: ${{ steps.fetch_commit_sha.outputs.commit_hash }} | |
steps: | |
- name: Fetch latest release from AirSane | |
id: fetch_release | |
run: | | |
echo "::group::Download latest release info to temporary file" | |
tmpfile=$(mktemp) | |
curl -sL https://api.github.com/repos/SimulPiscator/AirSane/releases/latest > "${tmpfile}" | |
echo "::endgroup::" | |
echo "::group::Extract meta information" | |
tag=$(jq -r .tag_name "${tmpfile}") | |
echo "Latest tag name: ${tag}" | |
echo "tag=${tag}" | tee -a $GITHUB_OUTPUT | |
echo "tag=${tag}" >> $GITHUB_ENV | |
echo "release_date=$(jq -r .published_at "${tmpfile}" | cut -d'T' -f1)" | tee -a $GITHUB_OUTPUT | |
echo "release_title=$(jq -r .name "${tmpfile}")" | tee -a $GITHUB_OUTPUT | |
echo "release_url=$(jq -r .html_url "${tmpfile}")" | tee -a $GITHUB_OUTPUT | |
echo "::endgroup::" | |
echo "::group::Cleanup" | |
rm -f "${tmpfile}" | |
echo "::endgroup::" | |
- name: Fetch commit SHA for the latest tag | |
id: fetch_commit_sha | |
run: | | |
tag=${{ env.tag }} | |
commit_hash=$(curl -sL "https://api.github.com/repos/SimulPiscator/AirSane/tags" | jq -r --arg TAG "$tag" '.[] | select(.name == $TAG) | .commit.sha') | |
echo "commit_hash=${commit_hash}" | tee -a $GITHUB_OUTPUT | |
- name: Checkout current repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if the release already exists | |
id: check_release | |
run: | | |
tag=${{ env.tag }} | |
if git rev-parse --verify "refs/tags/${tag}" >/dev/null 2>&1; then | |
echo "Release ${tag} already exists." | |
echo "exists=true" | tee -a $GITHUB_OUTPUT | |
else | |
echo "Release ${tag} does not yet exist." | |
echo "exists=false" | tee -a $GITHUB_OUTPUT | |
fi | |
update_makefile: | |
name: Update Makefile with latest hashes | |
runs-on: ubuntu-latest | |
needs: [check_release_exists] | |
if: needs.check_release_exists.outputs.release_exists != 'true' | |
steps: | |
- name: Checkout current repository | |
uses: actions/checkout@v4 | |
- name: Update Makefile with new release information | |
id: update_makefile | |
run: | | |
echo "::group::Retrieve parameters" | |
tag=${{ needs.check_release_exists.outputs.tag }} | |
release_date=${{ needs.check_release_exists.outputs.release_date }} | |
commit_hash=${{ needs.check_release_exists.outputs.commit_hash }} | |
echo "::endgroup::" | |
echo "::group::Replace values in Makefile" | |
sed -i "s/^PKG_RELEASE:=.*/PKG_RELEASE:=1/" airsaned/Makefile | |
sed -i "s/^PKG_VERSION:=.*/PKG_VERSION:=${tag#v}/" airsaned/Makefile | |
sed -i "s/^PKG_SOURCE_VERSION:=.*/PKG_SOURCE_VERSION:=${commit_hash}/" airsaned/Makefile | |
sed -i "s/^PKG_SOURCE_DATE:=.*/PKG_SOURCE_DATE:=${release_date}/" airsaned/Makefile | |
sed -i "s/^PKG_MIRROR_HASH:=.*/PKG_MIRROR_HASH:=skip/" airsaned/Makefile | |
echo "::endgroup::" | |
- name: Check for changes | |
id: check_changes | |
run: | | |
if git diff --exit-code; then | |
echo "No changes to commit." | |
echo "changes=false" | tee -a $GITHUB_OUTPUT | |
else | |
echo "changes=true" | tee -a $GITHUB_OUTPUT | |
fi | |
- name: Commit changes | |
if: steps.check_changes.outputs.changes == 'true' | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git commit -a -m "feat: update AirSane source reference to ${{ needs.check_release_exists.outputs.tag }}" | |
- name: Push changes | |
if: steps.check_changes.outputs.changes == 'true' | |
uses: ad-m/github-push-action@v0.8.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: master | |
build_all: | |
name: Build all packages for targets | |
uses: ./.github/workflows/build.yml | |
needs: update_makefile | |
create_release: | |
name: Create new release | |
runs-on: ubuntu-latest | |
needs: [check_release_exists, build_all] | |
if: needs.check_release_exists.outputs.release_exists == 'false' | |
steps: | |
- uses: actions/download-artifact@v4.1.7 | |
- run: | | |
mkdir release-packages | |
find . -type d -name '*.ipk.d' | while IFS= read -r pkd; do | |
cp -v $(find "$pkd" -name '*.ipk' -type f) release-packages/${pkd%.d} | |
done | |
- name: Create new release from tag | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ needs.check_release_exists.outputs.tag }} | |
name: ${{ needs.check_release_exists.outputs.release_title }} | |
draft: false | |
prerelease: false | |
body: | | |
Update AirSane to version ${{ needs.check_release_exists.outputs.tag }}, released on ${{ needs.check_release_exists.outputs.release_date }}. | |
[View source release here](${{ needs.check_release_exists.outputs.release_url }}). | |
files: release-packages/*.ipk |