-
Notifications
You must be signed in to change notification settings - Fork 47
188 lines (159 loc) · 6.15 KB
/
types.yaml
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Types Bindings
on:
push:
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
generate-tag:
runs-on: ubuntu-latest
permissions:
contents: write # Needed to push new tags
steps:
# Step 1: Checkout the contracts repository
- name: Checkout Contracts Repository
uses: actions/checkout@v4.1.7
with:
ref: ${{ env.BRANCH_NAME }}
# Step 2: Install Foundry
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
# Step 3: Install Solidity Libraries
- name: Install Solidity Libraries
run: forge install
# Step 4: Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v4.1.0
with:
node-version: 20
# Step 5: Install Node.js dependencies
- name: Install Node Dependencies
run: yarn install
# Step 6: Generate ABI from contracts
- name: Generate ABI
run: yarn abi:generate
# Step 7: Generate TypeScript bindings from ABI
- name: Generate TypeScript Bindings
run: yarn typechain
# Step 8: Checkout the lifi-contract-types repository
- name: Checkout lifi-contract-types Repository
uses: actions/checkout@v4.1.7
with:
repository: lifinance/lifi-contract-types
path: lifi-contract-types
ssh-key: ${{ secrets.SSH_REPO_TOKEN }}
ref: main
# Step 9: Copy generated types and ABI into the lifi-contract-types repo
- name: Copy Type Bindings and ABI
run: |
rm -rf lifi-contract-types/src/
mkdir -p lifi-contract-types/src
cp -r typechain/* lifi-contract-types/src/
cp diamond.json lifi-contract-types/dist/
- name: Verify File Status (for debugging)
run: |
cd lifi-contract-types
git status
# Step 10: Build the lifi-contract-types project
- name: Build Contract Types
run: cd lifi-contract-types && yarn install && yarn build
# Step 11: Retrieve the latest tag from the repository
- name: Retrieve Latest Tag
id: latest_release
run: |
# Fetch tags from the lifi-contract-types repository
RELEASE_JSON=$(curl https://api.github.com/repos/lifinance/lifi-contract-types/tags)
# Extract the latest tag name
LATEST_TAG=$(echo "$RELEASE_JSON" | jq -r '.[0].name')
# Handle beta versions for non-main branches
if [[ "$BRANCH_NAME" != "main" ]]; then
if [[ "$LATEST_TAG" != *"beta"* ]]; then
while read ITEM; do
TAG_NAME=$(jq -r '.name' <<< "$ITEM")
if [[ "$TAG_NAME" == "$LATEST_TAG-$beta"* ]]; then
LATEST_TAG=$TAG_NAME
break
fi
done <<<$(echo "$RELEASE_JSON" | jq -c -r '.[]')
fi
fi
# Check if LATEST_TAG is empty or null
if [[ -z "$LATEST_TAG" || "$LATEST_TAG" == "null" ]]; then
echo "ERROR: No latest tag found in the repository."
exit 1
fi
# Validate semver format
if [[ ! "$LATEST_TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-beta)?$ ]]; then
echo "ERROR: Invalid version format: $LATEST_TAG (not a valid semver format)"
exit 1
fi
echo "LATEST_TAG=$LATEST_TAG"
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
# Step 12: Increment the version number based on the commit message and branch
- name: Update Version
if: ${{ success() }}
env:
LATEST_TAG: ${{ env.LATEST_TAG }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
MESSAGE: ${{ github.event.head_commit.message }}
id: bump_version
run: |
# Remove leading "v" from LATEST_TAG for semver parsing
CURRENT_VERSION="${LATEST_TAG#v}"
echo "Current version: $CURRENT_VERSION"
VERSION_FRAGMENT=""
# Determine the type of version bump
if [[ "$BRANCH_NAME" == "main" ]]; then
if [[ "$MESSAGE" =~ "major" ]]; then
VERSION_FRAGMENT="major"
elif [[ "$MESSAGE" =~ "feat" ]]; then
VERSION_FRAGMENT="minor"
else
VERSION_FRAGMENT="patch"
fi
else
VERSION_FRAGMENT="beta"
fi
# Parse and increment the version
IFS='.' read -r MAJOR MINOR PATCH <<< "${CURRENT_VERSION//[^0-9.]/}"
if [[ "$VERSION_FRAGMENT" == "major" ]]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [[ "$VERSION_FRAGMENT" == "minor" ]]; then
MINOR=$((MINOR + 1))
PATCH=0
elif [[ "$VERSION_FRAGMENT" == "patch" ]]; then
PATCH=$((PATCH + 1))
elif [[ "$VERSION_FRAGMENT" == "beta" ]]; then
PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-beta"
else
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
fi
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
# Step 13: Push the updated version tag to the repository
- name: Push Updated Tag
if: ${{ success() }}
env:
NEW_VERSION: ${{ env.NEW_VERSION }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
MESSAGE: ${{ github.event.head_commit.message }}
run: |
cd lifi-contract-types
TMP=$(mktemp)
jq '.version="${NEW_VERSION}"' package.json > "$TMP" && mv "$TMP" package.json
git config user.name github-actions
git config user.email github-actions@github.com
echo "Updating version from $LATEST_TAG to $NEW_VERSION"
# git add src/*
# git add dist/*
# git add package.json
git add -A # Stage all changes, including deletions
git commit -m "actions: new contracts version $NEW_VERSION"
# Annotate and push the new tag
git tag -a "v$NEW_VERSION" -m "$MESSAGE"
git push origin tag "v$NEW_VERSION"
if [[ "$BRANCH_NAME" == "main" ]]; then
git push -u origin $BRANCH_NAME
fi