Skip to content
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
78 changes: 78 additions & 0 deletions .github/workflows/create-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This workflow creates and pushes a release tag using the push-release-tag.sh script.
# It can be triggered manually and will prompt for confirmation before creating the tag.

name: Create Release Tag

on:
workflow_dispatch:
inputs:
dry_run:
description: "Run in dry-run mode (show what would be done without actually creating/pushing the tag)"
required: false
type: boolean
default: true
confirm_release:
description: "Type 'YES' to confirm you want to create and push the release tag"
required: true
type: string
Comment on lines +6 to +17

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should configure the enviornment in this section so we don't specify it at each step.

The two env we have are development and production. The production env should be used on the release branch.


jobs:
check-branch:
runs-on: ubuntu-latest
environment: production
steps:
- name: Check if running on release branch
run: |
if [ "${{ github.ref }}" != "refs/heads/release" ]; then
echo "Error: This workflow can only be run from the 'release' branch."
echo "Current branch: ${{ github.ref }}"
echo "Please switch to the 'release' branch and try again."
exit 1
fi
echo "Running on release branch - proceeding with workflow."

create-release-tag:
runs-on: ubuntu-latest
needs: check-branch
environment: production
if: github.ref == 'refs/heads/release'

permissions:
contents: write # Required to create and push tags

steps:
- name: Validate confirmation
if: github.event.inputs.confirm_release != 'YES' && github.event.inputs.dry_run != 'true'
run: |
echo "Error: You must type 'YES' in the confirm_release input to proceed with creating a release tag."
echo "Received: '${{ github.event.inputs.confirm_release }}'"
exit 1

- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history and tags

- name: Make scripts executable
run: |
chmod +x scripts/push_release_tag.sh
chmod +x scripts/get_version.sh

- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Run push-release-tag script (dry-run)
if: github.event.inputs.dry_run == 'true'
run: |
echo "Running in dry-run mode..."
make push-release-tag DRY_RUN=--dry-run

- name: Run push-release-tag script
if: github.event.inputs.dry_run != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Creating and pushing release tag..."
# Override the interactive confirmation since we already confirmed via workflow input
echo "YES" | make push-release-tag
28 changes: 25 additions & 3 deletions .github/workflows/publish-to-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,38 @@ name: Deploy Python Package to AWS
on:
push:
tags:
- "*"
# e.g. v1.0.0, v1.0.1, v1.0.0-rc1, etc.
- "v[0-9]+.[0-9]+.[0-9]+*"
workflow_dispatch:

env:
PACKAGE_NAME: atlas
PACKAGE_NAME: layerlens

jobs:
validate:
runs-on: ubuntu-latest
environment: production
outputs:
release_tag: ${{ steps.set_release_tag.outputs.release_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for checking branch
- name: Set release tag
id: set_release_tag
# ensure the tag is valid (matches code, is on release branch, etc)
run: |
RELEASE_TAG=${GITHUB_REF#refs/tags/}
echo "Using tag: $RELEASE_TAG"
chmod +x ./scripts/validate_release_tag.sh
./scripts/validate_release_tag.sh "$RELEASE_TAG"
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT

deploy:
needs: validate
runs-on: ubuntu-latest
environment: development
environment: production

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "atlas"
name = "layerlens"
version = "1.0.2"
description = "The official Python library for the LayerLens Atlas API"
license = "Apache-2.0"
Expand Down
72 changes: 72 additions & 0 deletions scripts/push_release_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
set -euo pipefail

ROOT_DIR=$(git rev-parse --show-toplevel)

# Parse command line arguments
DRY_RUN=false

while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--dry-run]"
exit 1
;;
esac
done

git fetch --tags --prune

REPO_URL="https://github.com/LayerLens/atlas-python"
# e.g. v1.0.0, v1.0.1, etc.
TAG_PREFIX="v"
COMMIT=$(git rev-parse --short HEAD)
VERSION=$(bash "$ROOT_DIR/scripts/get_version.sh")
TAG="${TAG_PREFIX}${VERSION}"

if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Error: Tag $TAG already exists"
exit 1
fi

# Find the most recent version tag
LAST_RELEASE=$(git tag -l "${TAG_PREFIX}*" --sort=-v:refname | head -n 1)

echo "================================================"
echo " Atlas Python SDK Release"
echo "================================================"
echo "version: ${TAG}"
echo "commit: ${COMMIT}"
echo "code: ${REPO_URL}/commit/${COMMIT}"
echo "changeset: ${REPO_URL}/compare/${LAST_RELEASE}...${COMMIT}"

if [ "$DRY_RUN" = true ]; then
exit 0
fi

echo ""
echo ""
echo "Are you ready to release version ${VERSION}? Type 'YES' to continue:"
read -r CONFIRMATION

if [ "$CONFIRMATION" != "YES" ]; then
echo "Release cancelled."
exit 1
fi

# Create and push the tag
echo ""
echo "Creating and pushing tag ${TAG}"
echo ""

git tag "$TAG" "$COMMIT"
git push origin "$TAG"

echo ""
echo "Tag ${TAG} has been created and pushed to origin."
echo ""
63 changes: 63 additions & 0 deletions scripts/validate_release_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# Validate release requirements
# - Checks if the tag matches semantic versioning convention (v{major}.{minor}.{patch} with optional suffix)
# - Checks if the tag matches the version in the package
# - Ensures we're releasing from the release branch

set -e

# Get the tag from the first command line argument
if [ $# -eq 0 ]; then
echo "ERROR: Release tag argument not provided"
echo "Usage: $0 <release-tag>"
exit 1
fi

ROOT_DIR=$(git rev-parse --show-toplevel)

# Fetch the latest tags to ensure we're up to date
git fetch --tags --prune --force

TAG=$1

# Check if tag follows semantic versioning pattern (v{major}.{minor}.{patch} with optional suffix)
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "ERROR: Tag must follow semantic versioning pattern (v{major}.{minor}.{patch} with optional suffix)"
echo "Examples: v1.0.0, v2.1.3, v1.0.0-beta, v1.0.0-rc.1"
exit 1
fi

# Extract version without the 'v' prefix
VERSION=${TAG#v}

PACKAGE_VERSION=$(bash "$ROOT_DIR/scripts/get_version.sh")

# Check if the tag version matches the package version
if [ "$VERSION" != "$PACKAGE_VERSION" ]; then
echo "ERROR: Tag version ($VERSION) does not match package version ($PACKAGE_VERSION)"
exit 1
fi

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "release" ]; then
# If we're in detached HEAD state (which is likely in GitHub Actions with a tag),
# we need to check if the tag is on the release branch
if ! git rev-parse "$TAG" &>/dev/null; then
echo "ERROR: Tag $TAG does not exist in the repository"
exit 1
fi

TAG_COMMIT=$(git rev-parse "$TAG")

# Ensure we have release branch history
git fetch origin release --depth=1000

# Check if tag is on release branch
if ! git merge-base --is-ancestor "$TAG_COMMIT" origin/release; then
echo "ERROR: Tag $TAG is not on the release branch"
exit 1
fi
fi

# All checks passed
exit 0
Loading
Loading