Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

ci: add reusable workflow to create nightly tags in CalVer format (#3247)

Sanchith Hegde962592ab48ac
diff --git a/.github/git-cliff-changelog.toml b/.github/git-cliff-changelog.toml
index 1d7e4080cc..f9959eebfc 100644
--- a/.github/git-cliff-changelog.toml
+++ b/.github/git-cliff-changelog.toml
@@ -14,7 +14,7 @@ body = """
{% set commit_base_url = "https://github.com/juspay/hyperswitch/commit/" -%}
{% set compare_base_url = "https://github.com/juspay/hyperswitch/compare/" -%}
{% if version -%}
- ## {{ version | trim_start_matches(pat="v") }} ({{ timestamp | date(format="%Y-%m-%d") }})
+ ## {{ version }}
{% else -%}
## [unreleased]
{% endif -%}
@@ -69,7 +69,8 @@ commit_parsers = [
{ message = "^(?i)(refactor)", group = "<!-- 4 -->Refactors" },
{ message = "^(?i)(test)", group = "<!-- 5 -->Testing" },
{ message = "^(?i)(docs)", group = "<!-- 6 -->Documentation" },
- { message = "^(?i)(chore\\(version\\)): V[\\d]+\\.[\\d]+\\.[\\d]+", skip = true },
+ { message = "^(?i)(chore\\(version\\)): (V|v)[\\d]+\\.[\\d]+\\.[\\d]+", skip = true },
+ { message = "^(?i)(chore\\(version\\)): [0-9]{4}\\.[0-9]{2}\\.[0-9]{2}(\\.[0-9]+)?(-.+)?", skip = true },
{ message = "^(?i)(chore)", group = "<!-- 7 -->Miscellaneous Tasks" },
{ message = "^(?i)(build)", group = "<!-- 8 -->Build System / Dependencies" },
{ message = "^(?i)(ci)", skip = true },
@@ -79,7 +80,7 @@ protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# glob pattern for matching git tags
-tag_pattern = "v[0-9]*"
+tag_pattern = "[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}(\\.[0-9]+)?(-.+)?"
# regex for skipping tags
# skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
diff --git a/.github/workflows/release-new-version.yml b/.github/workflows/release-new-version.yml
deleted file mode 100644
index 2f8ae7e481..0000000000
--- a/.github/workflows/release-new-version.yml
+++ /dev/null
@@ -1,95 +0,0 @@
-name: Release a new version
-
-on:
- schedule:
- - cron: "30 14 * * 0-4" # Run workflow at 8 PM IST every Sunday-Thursday
-
- workflow_dispatch:
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.ref }}
- cancel-in-progress: true
-
-env:
- # Allow more retries for network requests in cargo (downloading crates) and
- # rustup (installing toolchains). This should help to reduce flaky CI failures
- # from transient network timeouts or other issues.
- CARGO_NET_RETRY: 10
- RUSTUP_MAX_RETRIES: 10
-
-jobs:
- create-release:
- name: Release a new version
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v4
- with:
- fetch-depth: 0
- token: ${{ secrets.AUTO_RELEASE_PAT }}
-
- - name: Install Rust
- uses: dtolnay/rust-toolchain@master
- with:
- toolchain: stable 2 weeks ago
-
- - name: Install cocogitto
- uses: baptiste0928/[email protected]
- with:
- crate: cocogitto
- version: 5.4.0
-
- - name: Set Git Configuration
- shell: bash
- run: |
- git config --local user.name 'github-actions'
- git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
-
- - name: Update Postman collection files from Postman directories
- shell: bash
- run: |
- # maybe we need to move this package.json as we need it in multiple workflows
- npm ci
- POSTMAN_DIR=postman/collection-dir
- POSTMAN_JSON_DIR=postman/collection-json
- NEWMAN_PATH=$(pwd)/node_modules/.bin
- export PATH=${NEWMAN_PATH}:${PATH}
- # generate postman collections for all postman directories
- for connector_dir in ${POSTMAN_DIR}/*
- do
- connector=$(basename ${connector_dir})
- newman dir-import ${POSTMAN_DIR}/${connector} -o ${POSTMAN_JSON_DIR}/${connector}.postman_collection.json
- done
-
- if git add postman && ! git diff --staged --quiet postman; then
- git commit --message 'test(postman): update postman collection files'
- echo "Changes detected and commited."
- fi
-
- - name: Obtain previous and new tag information
- shell: bash
- # Only consider tags on current branch when setting PREVIOUS_TAG
- run: |
- PREVIOUS_TAG="$(git tag --sort='version:refname' --merged | tail --lines 1)"
- if [[ "$(cog bump --auto --dry-run)" == *"No conventional commits for your repository that required a bump"* ]]; then
- NEW_TAG="$(cog bump --patch --dry-run)"
- else
- NEW_TAG="$(cog bump --auto --dry-run)"
- fi
- echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
- echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> $GITHUB_ENV
-
- - name: Update changelog and create tag
- shell: bash
- if: ${{ env.NEW_TAG != env.PREVIOUS_TAG }}
- # Remove prefix 'v' from 'NEW_TAG' as cog bump --version expects only the version number
- run: |
- cog bump --version ${NEW_TAG#v}
-
- - name: Push created commit and tag
- shell: bash
- if: ${{ env.NEW_TAG != env.PREVIOUS_TAG }}
- run: |
- git push
- git push --tags
diff --git a/.github/workflows/release-nightly-version-reusable.yml b/.github/workflows/release-nightly-version-reusable.yml
new file mode 100644
index 0000000000..deb8c44cc3
--- /dev/null
+++ b/.github/workflows/release-nightly-version-reusable.yml
@@ -0,0 +1,202 @@
+name: Create a nightly tag
+
+on:
+ workflow_call:
+ secrets:
+ app_id:
+ description: App ID for the GitHub app
+ required: true
+ app_private_key:
+ description: Private key for the GitHub app
+ required: true
+ outputs:
+ tag:
+ description: The tag that was created by the workflow
+ value: ${{ jobs.create-nightly-tag.outputs.tag }}
+
+env:
+ # Allow more retries for network requests in cargo (downloading crates) and
+ # rustup (installing toolchains). This should help to reduce flaky CI failures
+ # from transient network timeouts or other issues.
+ CARGO_NET_RETRY: 10
+ RUSTUP_MAX_RETRIES: 10
+
+ # The branch name that this workflow is allowed to run on.
+ # If the workflow is run on any other branch, this workflow will fail.
+ ALLOWED_BRANCH_NAME: main
+
+jobs:
+ create-nightly-tag:
+ name: Create a nightly tag
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Generate GitHub app token
+ id: generate_app_token
+ uses: actions/create-github-app-token@v1
+ with:
+ app-id: ${{ secrets.app_id }}
+ private-key: ${{ secrets.app_private_key }}
+
+ - name: Checkout repository
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Check if the workflow is run on an allowed branch
+ shell: bash
+ run: |
+ if [[ "${{github.ref}}" != "refs/heads/${ALLOWED_BRANCH_NAME}" ]]; then
+ echo "::error::This workflow is expected to be run from the '${ALLOWED_BRANCH_NAME}' branch. Current branch: '${{github.ref}}'"
+ exit 1
+ fi
+
+ - name: Check if the latest commit is a tag
+ shell: bash
+ run: |
+ if [[ -n "$(git tag --points-at HEAD)" ]]; then
+ echo "::error::The latest commit on the branch is already a tag"
+ exit 1
+ fi
+
+ - name: Install Rust
+ uses: dtolnay/rust-toolchain@master
+ with:
+ toolchain: stable
+
+ - name: Install git-cliff
+ uses: baptiste0928/[email protected]
+ with:
+ crate: git-cliff
+ version: 1.4.0
+
+ - name: Obtain previous and next tag information
+ shell: bash
+ run: |
+ # Calendar versioning format followed: `YYYY.0M.0D.MICRO`
+ # - MICRO version number starts from 0 (to allow for multiple tags in a single day)
+ # - Hotfixes or patches can be suffixed as `-hotfix1` or `-patch1` after the MICRO version number
+
+ CURRENT_UTC_DATE="$(date --utc '+%04Y.%02m.%02d')"
+
+ # Check if any tags exist on the current branch which contain the current UTC date
+ if ! git tag --merged | grep --quiet "${CURRENT_UTC_DATE}"; then
+ # Search for date-like tags (no strict checking), sort and obtain previous tag
+ PREVIOUS_TAG="$(
+ git tag --merged \
+ | grep --extended-regexp '[0-9]{4}\.[0-9]{2}\.[0-9]{2}' \
+ | sort --version-sort \
+ | tail --lines 1
+ )"
+
+ # No tags with current date exist, next tag will be just tagged with current date and micro version number 0
+ NEXT_MICRO_VERSION_NUMBER='0'
+ NEXT_TAG="${CURRENT_UTC_DATE}.${NEXT_MICRO_VERSION_NUMBER}"
+
+ else
+ # Some tags exist with current date, find out latest micro version number
+ PREVIOUS_TAG="$(
+ git tag --merged \
+ | grep "${CURRENT_UTC_DATE}" \
+ | sort --version-sort \
+ | tail --lines 1
+ )"
+ PREVIOUS_MICRO_VERSION_NUMBER="$(
+ echo -n "${PREVIOUS_TAG}" \
+ | sed --regexp-extended 's/[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.([0-9]+))?(-(.+))?/\2/g'
+ )"
+ # ^^^^^^^^ ^^^^^^^^ ^^^^^^^^ ^^^^^^ ^^^^
+ # YEAR MONTH DAY MICRO Any suffix, say `hotfix1`
+ #
+ # The 2nd capture group contains the micro version number
+
+ if [[ -z "${PREVIOUS_MICRO_VERSION_NUMBER}" ]]; then
+ # Micro version number is empty, set next micro version as 1
+ NEXT_MICRO_VERSION_NUMBER='1'
+ else
+ # Increment previous micro version by 1 and set it as next micro version
+ NEXT_MICRO_VERSION_NUMBER="$((PREVIOUS_MICRO_VERSION_NUMBER + 1))"
+ fi
+
+ NEXT_TAG="${CURRENT_UTC_DATE}.${NEXT_MICRO_VERSION_NUMBER}"
+ fi
+
+ echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> $GITHUB_ENV
+ echo "NEXT_TAG=${NEXT_TAG}" >> $GITHUB_ENV
+
+ - name: Generate changelog
+ shell: bash
+ run: |
+ # Generate changelog content and store it in `release-notes.md`
+ git-cliff --config '.github/git-cliff-changelog.toml' --strip header --tag "${NEXT_TAG}" "${PREVIOUS_TAG}^.." \
+ | sed "/## ${PREVIOUS_TAG}\$/,\$d" \
+ | sed '$s/$/\n- - -/' > release-notes.md
+
+ # Append release notes after the specified pattern in `CHANGELOG.md`
+ sed --in-place '0,/^- - -/!b; /^- - -/{
+ a
+ r release-notes.md
+ }' CHANGELOG.md
+ rm release-notes.md
+
+ # We make use of GitHub API calls to commit and tag the changelog instead of the simpler
+ # `git commit`, `git tag` and `git push` commands to have signed commits and tags
+ - name: Commit generated changelog and create tag
+ shell: bash
+ env:
+ GH_TOKEN: ${{ steps.generate_app_token.outputs.token }}
+ run: |
+ HEAD_COMMIT="$(git rev-parse 'HEAD^{commit}')"
+
+ # Create a tree based on the HEAD commit of the current branch and updated changelog file
+ TREE_SHA="$(
+ gh api \
+ --method POST \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ '/repos/{owner}/{repo}/git/trees' \
+ --raw-field base_tree="${HEAD_COMMIT}" \
+ --raw-field 'tree[][path]=CHANGELOG.md' \
+ --raw-field 'tree[][mode]=100644' \
+ --raw-field 'tree[][type]=blob' \
+ --field 'tree[][content][email protected]' \
+ --jq '.sha'
+ )"
+
+ # Create a commit to point to the above created tree
+ NEW_COMMIT_SHA="$(
+ gh api \
+ --method POST \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ '/repos/{owner}/{repo}/git/commits' \
+ --raw-field "message=chore(version): ${NEXT_TAG}" \
+ --raw-field "parents[]=${HEAD_COMMIT}" \
+ --raw-field "tree=${TREE_SHA}" \
+ --jq '.sha'
+ )"
+
+ # Update the current branch to point to the above created commit
+ # We disable forced update so that the workflow will fail if the branch has been updated since the workflow started
+ # (for example, new commits were pushed to the branch after the workflow execution started).
+ gh api \
+ --method PATCH \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ "/repos/{owner}/{repo}/git/refs/heads/${ALLOWED_BRANCH_NAME}" \
+ --raw-field "sha=${NEW_COMMIT_SHA}" \
+ --field 'force=false'
+
+ # Create a lightweight tag to point to the above created commit
+ gh api \
+ --method POST \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ '/repos/{owner}/{repo}/git/refs' \
+ --raw-field "ref=refs/tags/${NEXT_TAG}" \
+ --raw-field "sha=${NEW_COMMIT_SHA}"
+
+ - name: Set job outputs
+ shell: bash
+ run: |
+ echo "tag=${NEXT_TAG}" >> $GITHUB_OUTPUT
diff --git a/.github/workflows/release-nightly-version.yml b/.github/workflows/release-nightly-version.yml
new file mode 100644
index 0000000000..36a843469d
--- /dev/null
+++ b/.github/workflows/release-nightly-version.yml
@@ -0,0 +1,151 @@
+name: Create a nightly tag
+
+on:
+ schedule:
+ - cron: "0 0 * * 1-5" # Run workflow at 00:00 midnight UTC (05:30 AM IST) every Monday-Friday
+
+ workflow_dispatch:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+env:
+ # Allow more retries for network requests in cargo (downloading crates) and
+ # rustup (installing toolchains). This should help to reduce flaky CI failures
+ # from transient network timeouts or other issues.
+ CARGO_NET_RETRY: 10
+ RUSTUP_MAX_RETRIES: 10
+
+ # The branch name that this workflow is allowed to run on.
+ # If the workflow is run on any other branch, this workflow will fail.
+ ALLOWED_BRANCH_NAME: main
+
+jobs:
+ update-postman-collections:
+ name: Update Postman collection JSON files
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Generate GitHub app token
+ id: generate_app_token
+ uses: actions/create-github-app-token@v1
+ with:
+ app-id: ${{ secrets.HYPERSWITCH_BOT_APP_ID }}
+ private-key: ${{ secrets.HYPERSWITCH_BOT_APP_PRIVATE_KEY }}
+
+ - name: Checkout repository
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Check if the workflow is run on an allowed branch
+ shell: bash
+ run: |
+ if [[ "${{github.ref}}" != "refs/heads/${ALLOWED_BRANCH_NAME}" ]]; then
+ echo "::error::This workflow is expected to be run from the '${ALLOWED_BRANCH_NAME}' branch. Current branch: '${{github.ref}}'"
+ exit 1
+ fi
+
+ - name: Check if the latest commit is a tag
+ shell: bash
+ run: |
+ if [[ -n "$(git tag --points-at HEAD)" ]]; then
+ echo "::error::The latest commit on the branch is already a tag"
+ exit 1
+ fi
+
+ - name: Update Postman collection files from Postman directories
+ shell: bash
+ run: |
+ # maybe we need to move this package.json as we need it in multiple workflows
+ npm ci
+
+ POSTMAN_DIR="postman/collection-dir"
+ POSTMAN_JSON_DIR="postman/collection-json"
+ NEWMAN_PATH="$(pwd)/node_modules/.bin"
+ export PATH="${NEWMAN_PATH}:${PATH}"
+
+ # generate Postman collection JSON files for all Postman collection directories
+ for connector_dir in "${POSTMAN_DIR}"/*
+ do
+ connector="$(basename "${connector_dir}")"
+ newman dir-import "${POSTMAN_DIR}/${connector}" -o "${POSTMAN_JSON_DIR}/${connector}.postman_collection.json"
+ done
+
+ if git add postman && ! git diff --staged --quiet postman; then
+ echo "POSTMAN_COLLECTION_FILES_UPDATED=true" >> $GITHUB_ENV
+ echo "Postman collection files have been modified"
+ else
+ echo "Postman collection files have no modifications"
+ fi
+
+ - name: Commit updated Postman collections if modified
+ shell: bash
+ env:
+ GH_TOKEN: ${{ steps.generate_app_token.outputs.token }}
+ if: ${{ env.POSTMAN_COLLECTION_FILES_UPDATED == 'true' }}
+ run: |
+ # Obtain current HEAD commit SHA and use that as base tree SHA for creating a new tree
+ HEAD_COMMIT="$(git rev-parse 'HEAD^{commit}')"
+ UPDATED_TREE_SHA="${HEAD_COMMIT}"
+
+ # Obtain the flags to be passed to the GitHub CLI.
+ # Each line contains the flags to be used corresponding to the file.
+ lines="$(
+ git ls-files \
+ --format '--raw-field tree[][path]=%(path) --raw-field tree[][mode]=%(objectmode) --raw-field tree[][type]=%(objecttype) --field tree[][content]=@%(path)' \
+ postman/collection-json
+ )"
+
+ # Create a tree based on the HEAD commit of the current branch, using the contents of the updated Postman collections directory
+ while IFS= read -r line; do
+ # Split each line by space to obtain the flags passed to the GitHub CLI as an array
+ IFS=' ' read -ra flags <<< "${line}"
+
+ # Create a tree by updating each collection JSON file.
+ # The SHA of the created tree is used as the base tree SHA for updating the next collection file.
+ UPDATED_TREE_SHA="$(
+ gh api \
+ --method POST \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ '/repos/{owner}/{repo}/git/trees' \
+ --raw-field base_tree="${UPDATED_TREE_SHA}" \
+ "${flags[@]}" \
+ --jq '.sha'
+ )"
+ done <<< "${lines}"
+
+ # Create a commit to point to the tree with all updated collections
+ NEW_COMMIT_SHA="$(
+ gh api \
+ --method POST \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ '/repos/{owner}/{repo}/git/commits' \
+ --raw-field "message=chore(postman): update Postman collection files" \
+ --raw-field "parents[]=${HEAD_COMMIT}" \
+ --raw-field "tree=${UPDATED_TREE_SHA}" \
+ --jq '.sha'
+ )"
+
+ # Update the current branch to point to the above created commit.
+ # We disable forced update so that the workflow will fail if the branch has been updated since the workflow started
+ # (for example, new commits were pushed to the branch after the workflow execution started).
+ gh api \
+ --method PATCH \
+ --header 'Accept: application/vnd.github+json' \
+ --header 'X-GitHub-Api-Version: 2022-11-28' \
+ "/repos/{owner}/{repo}/git/refs/heads/${ALLOWED_BRANCH_NAME}" \
+ --raw-field "sha=${NEW_COMMIT_SHA}" \
+ --field 'force=false'
+
+ create-nightly-tag:
+ name: Create a nightly tag
+ uses: ./.github/workflows/release-nightly-version-reusable.yml
+ needs:
+ - update-postman-collections
+ secrets:
+ app_id: ${{ secrets.HYPERSWITCH_BOT_APP_ID }}
+ app_private_key: ${{ secrets.HYPERSWITCH_BOT_APP_PRIVATE_KEY }}