|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v6 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + fetch-tags: true |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + sudo apt-get update |
| 24 | + sudo apt-get install -y meson ninja-build gettext appstream desktop-file-utils libglib2.0-dev |
| 25 | +
|
| 26 | + - name: Get version from tag |
| 27 | + id: version |
| 28 | + run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 29 | + |
| 30 | + - name: Create source tarball |
| 31 | + run: | |
| 32 | + meson setup build |
| 33 | + meson dist -C build --no-tests --include-subprojects |
| 34 | +
|
| 35 | + # Find the generated tarball |
| 36 | + TARBALL=$(ls build/meson-dist/*.tar.xz) |
| 37 | +
|
| 38 | + # Rename to standard format |
| 39 | + mv "$TARBALL" "awakeonlan-${{ steps.version.outputs.version }}.tar.xz" |
| 40 | +
|
| 41 | + - name: Calculate SHA256 |
| 42 | + id: sha256 |
| 43 | + run: | |
| 44 | + HASH=$(sha256sum awakeonlan-${{ steps.version.outputs.version }}.tar.xz | awk '{print $1}') |
| 45 | + echo "hash=$HASH" >> $GITHUB_OUTPUT |
| 46 | + echo "SHA256: $HASH" |
| 47 | +
|
| 48 | + - name: Generate release notes |
| 49 | + id: release_notes |
| 50 | + run: | |
| 51 | + PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -2 | tail -1) |
| 52 | +
|
| 53 | + if [ -z "$PREVIOUS_TAG" ]; then |
| 54 | + PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD) |
| 55 | + fi |
| 56 | +
|
| 57 | + echo "Comparing $PREVIOUS_TAG..HEAD" |
| 58 | +
|
| 59 | + { |
| 60 | + echo 'notes<<EOF' |
| 61 | + git log --oneline --no-decorate "$PREVIOUS_TAG..HEAD" \ |
| 62 | + | grep -v '^[a-f0-9]\+ chore' \ |
| 63 | + | sed 's/^\([a-f0-9]\+\) \(.*\)/- \2 (\1)/' \ |
| 64 | + || echo "- Initial release" |
| 65 | + echo 'EOF' |
| 66 | + } >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Create GitHub release |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ github.token }} |
| 71 | + run: | |
| 72 | + gh release create ${{ steps.version.outputs.version }} \ |
| 73 | + awakeonlan-${{ steps.version.outputs.version }}.tar.xz \ |
| 74 | + --title "Awake on LAN ${{ steps.version.outputs.version }}" \ |
| 75 | + --notes "${{ steps.release_notes.outputs.notes }}" |
| 76 | +
|
| 77 | + - name: Update Homebrew formula |
| 78 | + run: | |
| 79 | + sed -i "s/version \".*\"/version \"${{ steps.version.outputs.version }}\"/" Formula/awakeonlan.rb |
| 80 | + sed -i "s/sha256 \".*\"/sha256 \"${{ steps.sha256.outputs.hash }}\"/" Formula/awakeonlan.rb |
| 81 | + CONTENT=$(base64 -w 0 < Formula/awakeonlan.rb) |
| 82 | + MAIN_OID=$(gh api graphql -f query='{ repository(owner:"logonoff", name:"awake-on-lan") { ref(qualifiedName:"refs/heads/main") { target { oid } } } }' --jq '.data.repository.ref.target.oid') |
| 83 | + jq -n \ |
| 84 | + --arg oid "$MAIN_OID" \ |
| 85 | + --arg content "$CONTENT" \ |
| 86 | + --arg version "${{ steps.version.outputs.version }}" \ |
| 87 | + '{ |
| 88 | + query: "mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid } } }", |
| 89 | + variables: { |
| 90 | + input: { |
| 91 | + branch: { repositoryNameWithOwner: "logonoff/awake-on-lan", branchName: "main" }, |
| 92 | + expectedHeadOid: $oid, |
| 93 | + message: { headline: ("chore: update formula to " + $version) }, |
| 94 | + fileChanges: { additions: [{ path: "Formula/awakeonlan.rb", contents: $content }] } |
| 95 | + } |
| 96 | + } |
| 97 | + }' | gh api graphql --input - |
| 98 | + git checkout -- Formula/awakeonlan.rb |
| 99 | + git pull --ff-only origin main |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Sync homebrew-bucket |
| 104 | + run: | |
| 105 | + gh api repos/logonoff/homebrew-bucket/dispatches \ |
| 106 | + -f event_type=sync |
| 107 | + env: |
| 108 | + GH_TOKEN: ${{ secrets.BUCKET_PAT }} |
| 109 | + |
| 110 | + - name: Check if next branch can be fast-forwarded |
| 111 | + id: check-next |
| 112 | + run: | |
| 113 | + if git ls-remote --exit-code origin next &>/dev/null; then |
| 114 | + git fetch origin next |
| 115 | + if git merge-base --is-ancestor origin/next HEAD; then |
| 116 | + echo "can_ff=true" >> "$GITHUB_OUTPUT" |
| 117 | + fi |
| 118 | + fi |
| 119 | +
|
| 120 | + - name: Fast-forward next branch |
| 121 | + if: steps.check-next.outputs.can_ff == 'true' |
| 122 | + run: git push origin HEAD:next |
| 123 | + env: |
| 124 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments