-
Notifications
You must be signed in to change notification settings - Fork 2
61 lines (54 loc) · 2.31 KB
/
check-release-version.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
# Workflow to check if the version in library.properties matches the latest release
# If it does not, deletes the release and the corresponding tag
name: Get Latest Release
on:
release:
types:
- published
jobs:
get_release:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository code
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Retrieve the latest release from the GitHub API
- name: Get latest release
id: get_latest_release
run: |
set -e
response=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest")
echo "Response: $response"
latest_release=$(echo "$response" | jq -r .tag_name)
echo "Latest release: $latest_release"
echo "::set-output name=release::$latest_release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Step 3: Check the version in the library.properties file and compare it with the latest release
- name: Check version in library.properties
id: compare_version
run: |
version=v$(cat library.properties | grep "version" | cut -d'=' -f2)
echo "Version in library.properties: $version"
echo "Version in release: ${{ steps.get_latest_release.outputs.release }}"
if [ "$version" == "${{ steps.get_latest_release.outputs.release }}" ]; then
echo "Versions match!"
else
echo "Versions don't match."
fi
echo "::set-output name=version::$version"
# Step 4: Delete the release if the versions don't match
- name: Delete release if failed
if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }}
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ steps.get_latest_release.outputs.release }}
github_token: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Step 5: Fail the workflow if the versions don't match
- name: Fail workflow if failed
if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }}
run: |
echo "Versions don't match. Failing the workflow."
exit 1