Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add publish CI for pg_analytics #68

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/publish-github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# workflows/publish-github-release.yml
#
# Publish GitHub Release
# Publish the ParadeDB pg_analytics GitHub Release.

name: Publish GitHub Release

on:
push:
branches:
- main
- dev
workflow_dispatch:

concurrency:
group: publish-github-release-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
publish-github-release:
name: Publish ParadeDB pg_analytics GitHub Release
runs-on: depot-ubuntu-latest-2

steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Set Environment
id: env
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "environment=prod" >> $GITHUB_OUTPUT
echo "Using prod configuration..."
else
echo "environment=dev" >> $GITHUB_OUTPUT
echo "Using dev configuration..."
fi

# We store the GitHub Release version number in GitHub Actions Variables. Since it's
# not possible for a GHA variable to be negative, we store the version of the next
# release, to allow 0-indexing. This is why we immediately release the version stored,
# and increment it after the GitHub release is created.
- name: Retrieve & Increment Release Version Number
id: version
run: |
if [[ "${{ steps.env.outputs.environment }}" == "prod" ]]; then
echo 'Using prod configuration...'
CURRENT_RELEASE_VERSION="${{ vars.VERSION_MAJOR }}.${{ vars.VERSION_MINOR }}.${{ vars.VERSION_PATCH }}"

# Increment GHA variable version by 0.0.1 for next release
GHA_VAR_NAME="VERSION_PATCH"
GHA_VAR_VALUE="$(( ${{ vars.VERSION_PATCH }} + 1 ))"
elif [[ "${{ steps.env.outputs.environment }}" == "dev" ]]; then
echo 'Using dev configuration...'
CURRENT_RELEASE_VERSION="${{ vars.VERSION_MAJOR }}.${{ vars.VERSION_MINOR }}.${{ vars.VERSION_PATCH }}-dev-rc.${{ vars.VERSION_DEV_RC }}"

# Increment GHA variable version by dev-rc.1 for next release
GHA_VAR_NAME="VERSION_DEV_RC"
GHA_VAR_VALUE="$(( ${{ vars.VERSION_DEV_RC }} + 1 ))"
else
echo "Error: Invalid branch" && false
fi

# Output the current release version to create the GitHub Release tag, and the new version to update GitHub Actions variable
echo "version=${CURRENT_RELEASE_VERSION}" >> $GITHUB_OUTPUT
echo "gha_var_name=${GHA_VAR_NAME}" >> $GITHUB_OUTPUT
echo "gha_var_value=${GHA_VAR_VALUE}" >> $GITHUB_OUTPUT

- name: Update Version Number in GitHub Actions Variables
env:
GH_TOKEN: ${{ secrets.GHA_CREATE_RELEASE_PAT }}
run: |
# on prod we update patch and reset dev RC to 0
if [[ "${{ steps.env.outputs.environment }}" == "prod" ]]; then
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/paradedb/paradedb/actions/variables/${{ steps.version.outputs.gha_var_name }} \
-f name='${{ steps.version.outputs.gha_var_name }}' \
-f value='${{ steps.version.outputs.gha_var_value }}'

gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/paradedb/paradedb/actions/variables/VERSION_DEV_RC \
-f name='VERSION_DEV_RC' \
-f value='0'
# on dev we only update dev RC
elif [[ "${{ steps.env.outputs.environment }}" == "dev" ]]; then
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/paradedb/paradedb/actions/variables/${{ steps.version.outputs.gha_var_name }} \
-f name='${{ steps.version.outputs.gha_var_name }}' \
-f value='${{ steps.version.outputs.gha_var_value }}'
else
echo "Error: Invalid branch" && false
fi

# We create the GitHub release last in case of failure in previous steps
- name: Create GitHub Release (prod only)
if: steps.env.outputs.environment == 'prod'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GHA_CREATE_RELEASE_PAT }}
Loading