-
Notifications
You must be signed in to change notification settings - Fork 1
68 lines (54 loc) · 2.33 KB
/
check_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
62
63
64
65
66
67
68
name: Check Version
on:
pull_request:
branches:
- main
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get version
id: yq
uses: mikefarah/yq@master
with:
cmd: yq -r '.version' 'pubspec.yaml'
- name: Print version
run: echo ${{ steps.yq.outputs.result }}
- name: Get Latest Tag
id: get_tag
run: |
REPO_NAME=${{ github.repository }}
JSON_RESPONSE=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases")
# Extract tag_name using Python
TAG_NAME=$(python -c "import sys, json; print(json.loads(sys.stdin.read())[0]['tag_name'])" <<< "$JSON_RESPONSE")
echo "latest=${TAG_NAME}">> $GITHUB_OUTPUT
# PAT=${{ secrets.GITHUB_TOKEN }}
# REPO_OWNER=${{ github.repository_owner }}
# LATEST_TAG=$(curl -s -H "Authorization: token $PAT" "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases" | jq -r ".tag_name")
# LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases" | jq -r '.[0].tag_name')
# echo "latest=${LATEST_TAG}">> $GITHUB_OUTPUT
- name: Print version
run: echo "provided_version=${{ steps.yq.outputs.result }} and latest_tag=${{ steps.get_tag.outputs.latest }}"
- name: Check Version
id: check_version
run: |
latest_tag=${{ steps.get_tag.outputs.latest }}
provided_version=${{ steps.yq.outputs.result }}
# Extract numerical version parts from the tags
latest_version=$(echo "$latest_tag" | sed 's/v\?\([0-9.]*\)[-a-zA-Z]*$/\1/')
provided_version=$(echo "$provided_version" | sed 's/v\?\([0-9.]*\)[-a-zA-Z]*$/\1/')
if [[ "$provided_version" == "$latest_version" ]]; then
echo "trigger_next_action=false">> $GITHUB_OUTPUT
exit 1
elif [[ "$provided_version" < "$latest_version" ]]; then
echo "trigger_next_action=false">> $GITHUB_OUTPUT
exit 1
else
echo "trigger_next_action=true">> $GITHUB_OUTPUT
fi
- name: Trigger Next Action
run: echo "Trigger Next Action ${{ steps.check_version.outputs.trigger_next_action }}"
env:
TRIGGER_NEXT_ACTION: ${{ steps.check_version.outputs.trigger_next_action }}