forked from polikasov/AirSane-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 5
144 lines (128 loc) · 5.64 KB
/
update_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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