This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
110 lines (101 loc) · 4.18 KB
/
check-zksolc-versions.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
name: Check zksolc-bin 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-zksolc-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get latest zksolc-bin version
id: get_latest_version
run: |
ZKSOLC_VERSION=$(curl -s https://api.github.com/repos/matter-labs/zksolc-bin/releases/latest | jq -r '.tag_name')
echo "ZKSOLC_VERSION=${ZKSOLC_VERSION}" >> $GITHUB_ENV
- name: Load previous zksolc-bin version
id: load_previous_version
run: |
if [ -f .zksolc-version ]; then
PREVIOUS_VERSION=$(cat .zksolc-version)
else
PREVIOUS_VERSION="none"
fi
echo "PREVIOUS_VERSION=${PREVIOUS_VERSION}" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
run: |
if [ "$ZKSOLC_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "New version found: $ZKSOLC_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'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_URL=$(gh pr list --state=open --head update-zksolc-${{ env.ZKSOLC_VERSION }} --json url --jq '.[0].url')
if [ -n "$PR_URL" ]; then
echo "PR already exists: $PR_URL"
echo "pr_exists=true" >> $GITHUB_ENV
echo "PR_URL=${PR_URL}" >> $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' && env.pr_exists == 'false'
run: |
BRANCH_EXIST=$(git ls-remote --heads origin update-zksolc-${{ env.ZKSOLC_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-zksolc-${{ env.ZKSOLC_VERSION }}
echo "${{ env.ZKSOLC_VERSION }}" > .zksolc-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 .zksolc-version
git commit -m "Update zksolc-bin to ${{ env.ZKSOLC_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-zksolc-${{ env.ZKSOLC_VERSION }}
- name: Create or Update Pull Request
if: env.update_required == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_BODY="A new version of zksolc-bin has been released: **${{ env.ZKSOLC_VERSION }}**. This PR updates the project with the latest version."
if [ "${{ env.pr_exists }}" == "true" ]; then
gh pr edit "${{ env.PR_URL }}" --body "$PR_BODY"
echo "Updated existing PR: ${{ env.PR_URL }}"
else
PR_URL=$(gh pr create \
--head update-zksolc-${{ env.ZKSOLC_VERSION }} \
--base develop \
--title "Update zksolc-bin to version ${{ env.ZKSOLC_VERSION }}" \
--body "$PR_BODY" \
--label "zksolc,update" \
--assignee "varex83,stranger80")
echo "Created new PR: $PR_URL"
fi
echo "PR_URL=${PR_URL}" >> $GITHUB_ENV