diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml new file mode 100644 index 0000000..8c0503b --- /dev/null +++ b/.github/workflows/create-release.yaml @@ -0,0 +1,79 @@ +on: + workflow_dispatch: + inputs: + bump_type: + description: "The kind of version bump we want. One of patch, minor, major." + required: true + +name: Create New Release + +jobs: + bump_version_pr: + name: Create version bump PR + runs-on: ubuntu-latest + env: + CARGO_NET_GIT_FETCH_WITH_CLI: "true" + steps: + - uses: actions/checkout@v4 + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - run: | + set -evo pipefail + + DATE_TODAY=$(date +"%Y-%m-%d") + + CARGO_VERSION="$(cargo metadata --format-version=1 | jq -r '.packages | .[] | select(.name == "ndc-clickhouse-cli") | .version')" + + BUMP_TYPE=${{ github.event.inputs.bump_type }} + + # Split the version into its components + IFS='.' read -r MAJOR MINOR PATCH <<< "$CARGO_VERSION" + + # Update the version based on the bump type + case $BUMP_TYPE in + major) + ((MAJOR++)) + MINOR=0 + PATCH=0 + ;; + minor) + ((MINOR++)) + PATCH=0 + ;; + patch) + ((PATCH++)) + ;; + *) + echo "Invalid bump type: $BUMP_TYPE" + exit 1 + ;; + esac + + # Construct the new version string + RELEASE_VERSION="$major.$minor.$patch" + + BRANCH_NAME="release-$RELEASE_VERSION" + + # Create a new feature branch for the changes. + git checkout -b $BRANCH_NAME + + # update version in Cargo.toml + sed -i 's/package.version = .*/package.version = "$RELEASE_VERSION"/' Cargo.toml + # update version in Cargo.lock + cargo update --workspace + + CHANGELOG_TEMPLATE="## [Unreleased]\n\n## [$RELEASE_VERSION] - $DATE_TODAY" + + sed -i "s/## \[Unreleased\]/$CHANGELOG_TEMPLATE/" CHANGELOG.md + + git add . + git commit -m "Release ClickHouse v$RELEASE_VERSION" + git push origin $BRANCH_NAME + + # create a pull-requests containing the updates. + gh pr create \ + --body "Release ClickHouse v$RELEASE_VERSION" \ + --title "Bump Clickhouse to $RELEASE_VERSION" \ + --head "$BRANCH_NAME" \ + --base "main" diff --git a/.github/workflows/deploy-stage.yaml b/.github/workflows/deploy-stage.yaml index e16c9af..03b8ae8 100644 --- a/.github/workflows/deploy-stage.yaml +++ b/.github/workflows/deploy-stage.yaml @@ -219,4 +219,153 @@ jobs: draft: false tag: v${{ steps.get-version.outputs.tagged_version }} body: ${{ steps.changelog-reader.outputs.changes }} - artifacts: release/artifacts/* \ No newline at end of file + artifacts: release/artifacts/* + create-cli-plugin-index-pr: + name: Create CLI Plugin Index PR + needs: + - release + runs-on: ubuntu-latest + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + steps: + - name: check out this repository + uses: actions/checkout@v4 + with: + path: ndc-clickhouse + + - name: check out cli-plugin-index + uses: actions/checkout@v4 + with: + repository: hasura/cli-plugin-index + path: cli-plugin-index + token: ${{ secrets.HASURA_BOT_TOKEN }} + + - uses: actions/download-artifact@v4 + with: + path: release/artifacts + merge-multiple: true + - run: | + set -evo pipefail + ROOT="$(pwd)" + + # we assume GITHUB_REF_NAME is the version number prefixed with `v`. This is checked in previous steps + BRANCH_NAME="clickhouse/release-$GITHUB_REF_NAME" + + RELEASE_HASH="$(cd ndc-clickhouse && git rev-parse HEAD)" + + # Change working directory to the target folder + cd cli-plugin-index + + git config --global user.name "hasura-bot" + git config --global user.email "accounts@hasura.io" + + # Create a new feature branch for the changes. + git checkout -b $BRANCH_NAME + + mkdir "plugins/clickhouse/$GITHUB_REF_NAME" + + cp "${ROOT}/release/manifest.yaml" "${ROOT}/cli-plugin-index/plugins/clickhouse/$GITHUB_REF_NAME/manifest.yaml" + + git add . + git commit -m "Release ClickHouse $GITHUB_REF_NAME" + git push origin $BRANCH_NAME + + # create a pull-requests containing the updates. + gh pr create \ + --body "Commit in ndc-clickhouse: https://github.com/hasura/ndc-clickhouse/commit/$RELEASE_HASH" \ + --title "Release ClickHouse $GITHUB_REF_NAME" \ + --head "$BRANCH_NAME" \ + --base "master" + + # scream into Slack if something goes wrong + - name: Report Status + if: always() + uses: ravsamhq/notify-slack-action@v2 + with: + status: ${{ job.status }} + notify_when: failure + notification_title: "😧 Error on <{repo_url}|{repo}>" + message_format: "🐴 *{workflow}* {status_message} for <{repo_url}|{repo}>" + env: + SLACK_WEBHOOK_URL: ${{ secrets.BROKEN_BUILD_SLACK_WEBHOOK_URL }} + + + create-ndc-hub-pr: + name: Create NDC-Hub PR + needs: + - release + runs-on: ubuntu-latest + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + steps: + - name: check out this repository + uses: actions/checkout@v4 + with: + path: ndc-clickhouse + + - name: check out ndc-hub + uses: actions/checkout@v4 + with: + repository: hasura/ndc-hub + path: ndc-hub + token: ${{ secrets.HASURA_BOT_TOKEN }} + + - uses: actions/download-artifact@v4 + with: + path: release/artifacts + merge-multiple: true + + - run: | + set -evo pipefail + ROOT="$(pwd)" + + # we assume GITHUB_REF_NAME is the version number prefixed with `v`. This is checked in previous steps + BRANCH_NAME="clickhouse/release-$GITHUB_REF_NAME" + + # These exported env vars are used for templating + # Release version is the same as tag name, minus leading v. + export RELEASE_VERSION=${GITHUB_REF_NAME:1}" + export RELEASE_HASH="$(cd ndc-clickhouse && git rev-parse HEAD)" + export CONNECTOR_DEFINITION_HASH=$(sha256sum ${ROOT}/release/artifacts/connector-definition.tgz | cut -f1 -d' ') + + # Change working directory to the target folder + cd ndc-hub + + git config --global user.name "hasura-bot" + git config --global user.email "accounts@hasura.io" + + # Create a new feature branch for the changes. + git checkout -b $BRANCH_NAME + + # create new connector definition + mkdir "${ROOT}/ndc-hub/registry/hasura/clickhouse/releases/$GITHUB_REF_NAME" + cat "${ROOT}/ci/templates/connector-packaging.json" | envsubst > "${ROOT}/ndc-hub/registry/hasura/clickhouse/releases/v$RELEASE_VERSION/connector-packaging.json" + + # modify metadata file to add new entry + UPDATED_METADATA=cat "${ROOT}/ndc-hub/registry/hasura/clickhouse/metadata.json" | + jq '.overview.latest_version = $GITHUB_REF_NAME' | + jq '.source_code.version |= [{tag: $GITHUB_REF_NAME, hash: $RELEASE_HASH, is_verified: true}] + .' + + # write out modified metadata file + echo "$UPDATED_METADATA" > "${ROOT}/ndc-hub/registry/hasura/clickhouse/metadata.json" + + git add . + git commit -m "Release ClickHouse $GITHUB_REF_NAME" + git push origin $BRANCH_NAME + + # create a pull-requests containing the updates. + gh pr create \ + --body "Commit in ndc-clickhouse: https://github.com/hasura/ndc-clickhouse/commit/$RELEASE_HASH" \ + --title "Release ClickHouse $GITHUB_REF_NAME" \ + --head "$BRANCH_NAME" \ + --base "main" + + # scream into Slack if something goes wrong + - name: Report Status + if: always() + uses: ravsamhq/notify-slack-action@v2 + with: + status: ${{ job.status }} + notify_when: failure + notification_title: "😧 Error on <{repo_url}|{repo}>" + message_format: "🐴 *{workflow}* {status_message} for <{repo_url}|{repo}>" + env: + SLACK_WEBHOOK_URL: ${{ secrets.BROKEN_BUILD_SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/tag-release.yaml b/.github/workflows/tag-release.yaml new file mode 100644 index 0000000..8e9340b --- /dev/null +++ b/.github/workflows/tag-release.yaml @@ -0,0 +1,35 @@ +# on merge to main from a branch named release-*, create a tag based on version in Cargo.toml +name: Bump version +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + build: + if: github.event.pull_request.merged == true + runs-on: ubuntu-22.04 + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: '0' + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Read version from Cargo.toml + id: read-version + run: | + CARGO_VERSION="$(cargo metadata --format-version=1 | jq -r '.packages | .[] | select(.name == "ndc-clickhouse-cli") | .version')" + echo("::set-output name=RELEASE_VERSION::$CARGO_VERSION") + + - name: Bump version and push tag + uses: anothrNick/github-tag-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_BRANCHES: release-.* + CUSTOM_TAG: v${{ steps.read-version.outputs.RELEASE_VERSION }} \ No newline at end of file diff --git a/ci/templates/connector-packaging.json b/ci/templates/connector-packaging.json new file mode 100644 index 0000000..b17770a --- /dev/null +++ b/ci/templates/connector-packaging.json @@ -0,0 +1,11 @@ +{ + "version": "$RELEASE_VERSION", + "uri": "https://github.com/hasura/ndc-clickhouse/releases/download/v$RELEASE_VERSION/connector-definition.tgz", + "checksum": { + "type": "sha256", + "value": "$CONNECTOR_DEFINITION_HASH" + }, + "source": { + "hash": "$RELEASE_HASH" + } +} \ No newline at end of file