From 296ced30bb7abcd34fd497e98ce07bfea0ddf54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 27 Nov 2024 10:52:13 +0700 Subject: [PATCH 1/6] test --- .github/workflows/types.yaml | 132 +++++++++++++++++++++++------------ 1 file changed, 87 insertions(+), 45 deletions(-) diff --git a/.github/workflows/types.yaml b/.github/workflows/types.yaml index 074b2a142..42d1cf277 100644 --- a/.github/workflows/types.yaml +++ b/.github/workflows/types.yaml @@ -10,111 +10,153 @@ jobs: generate-tag: runs-on: ubuntu-latest permissions: - contents: read + contents: write # Needed to push new tags steps: - - name: Checkout contracts repository - uses: actions/checkout@v4 + # 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 - - name: Install Solidity Libs + # 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 - - name: Install Node deps + # 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 - - name: Generate types bindings + # Step 7: Generate TypeScript bindings from ABI + - name: Generate TypeScript Bindings run: yarn typechain - - name: Checkout lifi-contract-types repository - uses: actions/checkout@v4 + # 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 - - name: Copy types bindings + # Step 9: Copy generated types and ABI into the lifi-contract-types repo + - name: Copy Type Bindings and ABI run: | rm -r lifi-contract-types/src/ mv typechain lifi-contract-types/src cp diamond.json lifi-contract-types/dist/ - - name: Build contract types + # Step 10: Build the lifi-contract-types project + - name: Build Contract Types run: cd lifi-contract-types && yarn install && yarn build - - name: Retrieve latest Tag + # Step 11: Retrieve the latest tag from the repository + - name: Retrieve Latest Tag id: latest_release run: | - # fetch tag releases - release_json=$(curl https://api.github.com/repos/lifinance/lifi-contract-types/tags) + # Fetch tags from the lifi-contract-types repository + RELEASE_JSON=$(curl https://api.github.com/repos/lifinance/lifi-contract-types/tags) - # get the latest tag - LATEST_TAG=$(echo "$release_json" | jq -r '.[0].name') + # Extract the latest tag name + LATEST_TAG=$(echo "$RELEASE_JSON" | jq -r '.[0].name') - # we need to make sure that on staging we're going to update a -beta version, if any + # Handle beta versions for non-main branches if [[ "$BRANCH_NAME" != "main" ]]; then - # if it has already "-beta", no other action is required, since it means - # that we're already going to update the latest staging release if [[ "$LATEST_TAG" != *"beta"* ]]; then - # otherwise, start looping through the tags and search for the latest -beta tag - while read item; do - tag_name=$(jq -r '.name' <<< "$item") - # check if there's already a latest tag beta release - # and, if present, use it instead of the main one - # if we end up without any latest beta tag, we will create a beta release from the latest tag - if [[ "$tag_name" == "$LATEST_TAG-$beta"* ]]; then - LATEST_TAG=$tag_name + 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 '.[]') + done <<<$(echo "$RELEASE_JSON" | jq -c -r '.[]') fi fi - echo "latest tag: $LATEST_TAG" - echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV - - name: Update version + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV + + # Step 12: Increment the version number based on the commit message and branch + - name: Update Version env: + LATEST_TAG: ${{ env.LATEST_TAG }} + BRANCH_NAME: ${{ env.BRANCH_NAME }} MESSAGE: ${{ github.event.head_commit.message }} id: bump_version - uses: christian-draeger/increment-semantic-version@1.1.0 - with: - current-version: '${{ env.LATEST_TAG }}' - version-fragment: "${{ env.BRANCH_NAME == 'main' && (contains(env.MESSAGE, 'major') && 'major' || contains(env.MESSAGE, 'feat') && 'feature' || 'bug') || 'beta' }}" + run: | + # Default to version 0.0.0 if no tag is found + CURRENT_VERSION=${LATEST_TAG:-"0.0.0"} + VERSION_FRAGMENT="" - - name: Push tag + # 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" >> $GITHUB_ENV + + # Step 13: Push the updated version tag to the repository + - name: Push Updated Tag env: + NEW_VERSION: ${{ env.NEW_VERSION }} + BRANCH_NAME: ${{ env.BRANCH_NAME }} MESSAGE: ${{ github.event.head_commit.message }} - if: steps.bump_version.outputs.next-version run: | cd lifi-contract-types - tmp=$(mktemp) - jq '.version="${{ steps.bump_version.outputs.next-version }}"' package.json > "$tmp" && mv "$tmp" package.json + 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 ${{ env.LATEST_TAG }} to ${{ steps.bump_version.outputs.next-version }}' + echo "Updating version from $LATEST_TAG to $NEW_VERSION" git add src/* git add dist/* git add package.json - git commit -m 'actions: new contracts version ${{ steps.bump_version.outputs.next-version }}' - - # Sanitize the commit message by removing single quotes - COMMIT_MSG=$(echo "$MESSAGE" | sed "s/'//g") + git commit -m "actions: new contracts version $NEW_VERSION" - git tag -a v${{ steps.bump_version.outputs.next-version }} -m "$MESSAGE" - git push origin tag v${{ steps.bump_version.outputs.next-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 From 3e989bc4c7a74dcdc0533b9aebe04b40e5ef7268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 27 Nov 2024 10:59:45 +0700 Subject: [PATCH 2/6] action should fail if latest tag cannot be retrieved --- .github/workflows/types.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/types.yaml b/.github/workflows/types.yaml index 42d1cf277..ad966c2be 100644 --- a/.github/workflows/types.yaml +++ b/.github/workflows/types.yaml @@ -88,10 +88,18 @@ jobs: 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 + + 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 }} @@ -138,6 +146,7 @@ jobs: # 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 }} From f4f597a268777b87f5690d79ff6d91b801a2ca43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 27 Nov 2024 11:28:38 +0700 Subject: [PATCH 3/6] minor fix --- .github/workflows/types.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/types.yaml b/.github/workflows/types.yaml index ad966c2be..aff3bcfa3 100644 --- a/.github/workflows/types.yaml +++ b/.github/workflows/types.yaml @@ -106,8 +106,6 @@ jobs: MESSAGE: ${{ github.event.head_commit.message }} id: bump_version run: | - # Default to version 0.0.0 if no tag is found - CURRENT_VERSION=${LATEST_TAG:-"0.0.0"} VERSION_FRAGMENT="" # Determine the type of version bump From 34fbaed7902417a0e09c8035d47195d240d2300e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 27 Nov 2024 11:31:50 +0700 Subject: [PATCH 4/6] minor fix#2 --- .github/workflows/types.yaml | 6 + .../types.oldVersion.yml | 120 ++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 .github/workflows_deactivated/types.oldVersion.yml diff --git a/.github/workflows/types.yaml b/.github/workflows/types.yaml index aff3bcfa3..dc3fe6792 100644 --- a/.github/workflows/types.yaml +++ b/.github/workflows/types.yaml @@ -94,6 +94,12 @@ jobs: exit 1 fi + # Validate semver format + if [[ ! "$LATEST_TAG" =~ ^[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 diff --git a/.github/workflows_deactivated/types.oldVersion.yml b/.github/workflows_deactivated/types.oldVersion.yml new file mode 100644 index 000000000..074b2a142 --- /dev/null +++ b/.github/workflows_deactivated/types.oldVersion.yml @@ -0,0 +1,120 @@ +name: Types Bindings + +on: + push: + +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + +jobs: + generate-tag: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout contracts repository + uses: actions/checkout@v4 + with: + ref: ${{ env.BRANCH_NAME }} + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + + - name: Install Solidity Libs + run: forge install + + - name: Setup Node.js + uses: actions/setup-node@v4.1.0 + with: + node-version: 20 + + - name: Install Node deps + run: yarn install + + - name: Generate ABI + run: yarn abi:generate + + - name: Generate types bindings + run: yarn typechain + + - name: Checkout lifi-contract-types repository + uses: actions/checkout@v4 + with: + repository: lifinance/lifi-contract-types + path: lifi-contract-types + ssh-key: ${{ secrets.SSH_REPO_TOKEN }} + ref: main + + - name: Copy types bindings + run: | + rm -r lifi-contract-types/src/ + mv typechain lifi-contract-types/src + cp diamond.json lifi-contract-types/dist/ + + - name: Build contract types + run: cd lifi-contract-types && yarn install && yarn build + + - name: Retrieve latest Tag + id: latest_release + run: | + # fetch tag releases + release_json=$(curl https://api.github.com/repos/lifinance/lifi-contract-types/tags) + + # get the latest tag + LATEST_TAG=$(echo "$release_json" | jq -r '.[0].name') + + # we need to make sure that on staging we're going to update a -beta version, if any + if [[ "$BRANCH_NAME" != "main" ]]; then + # if it has already "-beta", no other action is required, since it means + # that we're already going to update the latest staging release + if [[ "$LATEST_TAG" != *"beta"* ]]; then + # otherwise, start looping through the tags and search for the latest -beta tag + while read item; do + tag_name=$(jq -r '.name' <<< "$item") + # check if there's already a latest tag beta release + # and, if present, use it instead of the main one + # if we end up without any latest beta tag, we will create a beta release from the latest tag + if [[ "$tag_name" == "$LATEST_TAG-$beta"* ]]; then + LATEST_TAG=$tag_name + break + fi + done <<<$(echo "$release_json" | jq -c -r '.[]') + fi + fi + echo "latest tag: $LATEST_TAG" + echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV + + - name: Update version + env: + MESSAGE: ${{ github.event.head_commit.message }} + id: bump_version + uses: christian-draeger/increment-semantic-version@1.1.0 + with: + current-version: '${{ env.LATEST_TAG }}' + version-fragment: "${{ env.BRANCH_NAME == 'main' && (contains(env.MESSAGE, 'major') && 'major' || contains(env.MESSAGE, 'feat') && 'feature' || 'bug') || 'beta' }}" + + - name: Push tag + env: + MESSAGE: ${{ github.event.head_commit.message }} + if: steps.bump_version.outputs.next-version + run: | + cd lifi-contract-types + tmp=$(mktemp) + jq '.version="${{ steps.bump_version.outputs.next-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 ${{ env.LATEST_TAG }} to ${{ steps.bump_version.outputs.next-version }}' + git add src/* + git add dist/* + git add package.json + git commit -m 'actions: new contracts version ${{ steps.bump_version.outputs.next-version }}' + + # Sanitize the commit message by removing single quotes + COMMIT_MSG=$(echo "$MESSAGE" | sed "s/'//g") + + git tag -a v${{ steps.bump_version.outputs.next-version }} -m "$MESSAGE" + git push origin tag v${{ steps.bump_version.outputs.next-version }} + if [[ "$BRANCH_NAME" == "main" ]]; then + git push -u origin $BRANCH_NAME + fi From 185d7313170792282771c684172e10b2bc663632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 27 Nov 2024 11:36:21 +0700 Subject: [PATCH 5/6] update regex --- .github/workflows/types.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/types.yaml b/.github/workflows/types.yaml index dc3fe6792..1d2f3dea5 100644 --- a/.github/workflows/types.yaml +++ b/.github/workflows/types.yaml @@ -95,7 +95,7 @@ jobs: fi # Validate semver format - if [[ ! "$LATEST_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-beta)?$ ]]; then + 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 From 067252ea73f80a73766aa7feb1465f4fc6e5d2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Wed, 27 Nov 2024 11:42:26 +0700 Subject: [PATCH 6/6] bugfix --- .github/workflows/types.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/types.yaml b/.github/workflows/types.yaml index 1d2f3dea5..3cc5ab3a5 100644 --- a/.github/workflows/types.yaml +++ b/.github/workflows/types.yaml @@ -112,6 +112,10 @@ jobs: 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 @@ -146,6 +150,7 @@ jobs: 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