-
Notifications
You must be signed in to change notification settings - Fork 30
101 lines (89 loc) · 3.62 KB
/
check-scarb-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
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
name: Check Scarb Version
on:
schedule:
- cron: '0 0 * * *' # Runs at midnight every day
workflow_dispatch: # Allows for manual triggering
permissions:
contents: write
pull-requests: write
jobs:
check-scarb-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get the latest version of Scarb
id: get_latest_version
run: |
SCARB_VERSION=$(curl -s https://api.github.com/repos/software-mansion/scarb/releases/latest | jq -r '.tag_name')
echo "SCARB_VERSION=${SCARB_VERSION}" >> $GITHUB_ENV
- name: Load previous Scarb version
id: load_previous_version
run: |
if [ -f .scarb-version ]; then
PREVIOUS_VERSION=$(cat .scarb-version)
else
PREVIOUS_VERSION="none"
fi
echo "PREVIOUS_VERSION=${PREVIOUS_VERSION}" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
run: |
if [ "$SCARB_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "New version found: $SCARB_VERSION"
echo "update_required=true" >> $GITHUB_ENV
else
echo "No update required"
echo "update_required=false" >> $GITHUB_ENV
fi
- name: Check if PR already exists
id: check_pr_exists
if: env.update_required == 'true'
run: |
PR_EXIST=$(gh pr list --state=open --head update-scarb-${{ env.SCARB_VERSION }} | wc -l)
if [ "$PR_EXIST" -gt 0 ]; then
echo "PR already exists."
echo "pr_exists=true" >> $GITHUB_ENV
else
echo "No PR exists."
echo "pr_exists=false" >> $GITHUB_ENV
fi
- name: Check if branch already exists
id: check_branch_exists
if: env.update_required == 'true'
run: |
BRANCH_EXIST=$(git ls-remote --heads origin update-scarb-${{ env.SCARB_VERSION }} | wc -l)
if [ "$BRANCH_EXIST" -gt 0 ]; then
echo "Branch already exists."
echo "branch_exists=true" >> $GITHUB_ENV
else
echo "Branch does not exist."
echo "branch_exists=false" >> $GITHUB_ENV
fi
- name: Create a new branch for the update
if: env.update_required == 'true' && env.pr_exists == 'false' && env.branch_exists == 'false'
run: |
git checkout -b update-scarb-${{ env.SCARB_VERSION }}
echo "${{ env.SCARB_VERSION }}" > .scarb-version
- name: Commit changes
if: env.update_required == 'true' && env.pr_exists == 'false' && env.branch_exists == 'false'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .scarb-version
git commit -m "Update Scarb version to ${{ env.SCARB_VERSION }}"
- name: Push changes to new branch
if: env.update_required == 'true' && env.pr_exists == 'false' && env.branch_exists == 'false'
run: |
git push origin update-scarb-${{ env.SCARB_VERSION }}
- name: Create Pull Request
if: env.update_required == 'true' && env.pr_exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--head update-scarb-${{ env.SCARB_VERSION }} \
--base develop \
--title "Update Scarb to version ${{ env.SCARB_VERSION }}" \
--body "A new version of Scarb has been released: **${{ env.SCARB_VERSION }}**.\nThis PR updates the project with the latest version." \
--label "scarb,update"