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
4 changes: 2 additions & 2 deletions .github/config/mountainash_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Private Package Dependencies
dependencies:
- name: mountainash-constants
org-name: mountainash-io
# - name: mountainash-constants
# org-name: mountainash-io
# - name: mountainash-data
# org-name: mountainash-io
# - name: mountainash-settings
Expand Down
144 changes: 66 additions & 78 deletions .github/workflows/build-and-release-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,40 @@ on:
pull_request:
types: [closed]
branches:
- 'main'
- 'develop'
- 'release*'
- 'feature*'
- 'bugfix*'
- 'hotfix*'
- "main"
- "develop"
- "release*"
- "feature*"
- "bugfix*"
- "hotfix*"

# Add manual workflow dispatch with fallback branch selection
workflow_dispatch:
inputs:

release_type:
description: 'Type of release to create'
description: "Type of release to create"
required: true
default: 'production'
type: 'choice'
default: "production"
type: "choice"
options:
- production
- rc
- beta
- beta

source_branch:
description: 'Branch containing code to release'
description: "Branch containing code to release"
required: true
default: 'main'
type: 'string'
default: "main"
type: "string"

fallback_branch:
description: 'Fallback branch to use for dependencies'
description: "Fallback branch to use for dependencies"
required: true
default: 'main'
default: "main"
type: choice
options:
- develop
- main

- develop
- main

jobs:
build-and-release:
Expand All @@ -50,12 +48,11 @@ jobs:
matrix:
os: [ubuntu-24.04]
python-version: ["3.12"]

env:
BUILD_ENV: 'build_github'
BUILD_ENV: "build_github"

steps:

# ======================================================
# INITIALIZE

Expand All @@ -70,22 +67,20 @@ jobs:
with:
python-version: ${{ matrix.python-version }}


- name: Checkout Repository (PR)
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 0

- name: Checkout Repository (Manual)
if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.source_branch }}
fetch-depth: 0


- name: Set Branch Vars
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
Expand All @@ -102,45 +97,40 @@ jobs:
echo "MANUAL_RELEASE_TYPE=" >> $GITHUB_ENV
fi



# ======================================================
# DEPENDENCIES

- name: Python Dependencies
run: |
pip install hatchling==1.25.0
pip install hatch==1.14.2
pip install hatchling==1.29.0
pip install hatch==1.16.5

# Checkout Mountain Ash Dependencies
- name: Load Dependencies
id: deps
uses: ./.github/actions/load-dependencies
with:
config-path: .github/config/mountainash_dependencies.yml



- name: Checkout Dependencies
uses: ./.github/actions/checkout-dependencies
with:
dependencies: ${{ steps.deps.outputs.dependencies }}
target-branch: ${{ env.TARGET_BRANCH }}
default-branch: ${{ env.FALLBACK_BRANCH }}
token: ${{ secrets.CLONE_PRIVATE_REPOS_TOKEN }}
org-name: ${{ env.ORGNAME }}
# - name: Load Dependencies
# id: deps
# uses: ./.github/actions/load-dependencies
# with:
# config-path: .github/config/mountainash_dependencies.yml

# - name: Checkout Dependencies
# uses: ./.github/actions/checkout-dependencies
# with:
# dependencies: ${{ steps.deps.outputs.dependencies }}
# target-branch: ${{ env.TARGET_BRANCH }}
# default-branch: ${{ env.FALLBACK_BRANCH }}
# token: ${{ secrets.CLONE_PRIVATE_REPOS_TOKEN }}
# org-name: ${{ env.ORGNAME }}

# ======================================================
# CONFIGURE RELEASE


- name: Get Base Version
id: base_version
run: |
# BASE_VERSION=$(python -c "import sys; sys.path.append('src'); from ${{env.PACKAGE_SRCDIR}}.__version__ import __version__; print(__version__)")
BASE_VERSION=$(hatch version)
echo "BASE_VERSION=${BASE_VERSION}" >> $GITHUB_ENV

# Validate semantic version format
if [[ ! "$BASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Base version must be in semantic version format (X.Y.Z)"
Expand All @@ -156,7 +146,7 @@ jobs:
IS_PRERELEASE="true"
RELEASE_TITLE=""
RELEASE_DESCRIPTION=""

# Function to get latest version number
get_latest_version() {
local prefix="$1"
Expand All @@ -165,12 +155,12 @@ jobs:
"https://api.github.com/repos/${{ github.repository }}/releases" | \
jq -r --arg prefix "$prefix" --arg suffix "$suffix" \
"map(select(.tag_name | startswith(\$prefix) and contains(\$suffix))) | .[0].tag_name" || echo ""
}
}

# Check for manual workflow run
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Using manual release type: ${{ env.MANUAL_RELEASE_TYPE }}"

case "${{ env.MANUAL_RELEASE_TYPE }}" in
"production")
RELEASE_TYPE="production"
Expand Down Expand Up @@ -216,7 +206,7 @@ jobs:
exit 1
fi
;;

"develop")
RELEASE_TYPE="rc"
# Get latest RC number for this version
Expand All @@ -226,7 +216,7 @@ jobs:
RELEASE_TITLE="Release Candidate"
RELEASE_DESCRIPTION="Release candidate for testing and validation"
;;

*)
if [[ "{{ env.SOURCE_BRANCH }}" == feature/* || "$SOURCE_BRANCH" == bugfix/* ]]; then
RELEASE_TYPE="beta"
Expand All @@ -242,10 +232,10 @@ jobs:
;;
esac
fi

# Set full version
FULL_VERSION="${BASE_VERSION}${VERSION_SUFFIX:+$VERSION_SUFFIX}"

# Output all variables
{
echo "RELEASE_TYPE=${RELEASE_TYPE}"
Expand All @@ -255,7 +245,7 @@ jobs:
echo "RELEASE_TITLE=${RELEASE_TITLE}"
echo "RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION}"
} >> $GITHUB_OUTPUT

echo "VERSION=${FULL_VERSION}" >> $GITHUB_ENV

- name: Validate Release
Expand All @@ -265,7 +255,7 @@ jobs:
echo "Error: Tag v${{ env.VERSION }} already exists"
exit 1
fi

# Check if release already exists
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ env.VERSION }}" \
Expand Down Expand Up @@ -304,7 +294,6 @@ jobs:
echo "Checking version from Hatch:"
hatch version


- name: Build Package
id: build
run: |
Expand Down Expand Up @@ -347,19 +336,18 @@ jobs:
prerelease: ${{ steps.release_config.outputs.IS_PRERELEASE }}
body: |
${{ steps.release_config.outputs.RELEASE_DESCRIPTION }}

## Release Details
- Type: ${{ steps.release_config.outputs.RELEASE_TYPE }}
- Source Branch: ${{ github.head_ref }}
- Target Branch: ${{ github.base_ref }}
- Version: ${{ env.VERSION }}

## Package Information
- Package: ${{ env.PACKAGE_NAME }}
- Base Version: ${{ env.BASE_VERSION }}
${{ steps.release_config.outputs.VERSION_SUFFIX && format('- Version Suffix: {0}', steps.release_config.outputs.VERSION_SUFFIX) || '' }}


- name: Upload Package
uses: actions/upload-release-asset@v1
env:
Expand Down Expand Up @@ -395,46 +383,46 @@ jobs:
# Configure git
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"

# Clone the wheels repository
git clone https://x-access-token:${{ secrets.CLONE_PRIVATE_REPOS_TOKEN }}@github.com/${{ env.ORGNAME }}/mountainash-wheels.git wheels-repo

# Go to the wheels repository
cd wheels-repo

# Generate a unique branch name using a timestamp
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BRANCH_NAME="release/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-${TIMESTAMP}"

# Create a new branch for this release
git checkout -b $BRANCH_NAME

# Create package directory if it doesn't exist
mkdir -p ${{ env.PACKAGE_NAME }}

# Copy the newly built wheel to the repository
cp ../${{ steps.build.outputs.WHEEL_FILE }} ${{ env.PACKAGE_NAME }}/

# Add the new wheel file
git add .

# Commit the changes
git commit -m "Add ${{ steps.build.outputs.WHEEL_FILENAME }} to wheels repository"

# Push the branch to the repository
git push -u origin $BRANCH_NAME

# Export the branch name for later steps
echo "WHEELS_BRANCH=${BRANCH_NAME}" >> $GITHUB_ENV

- name: Create Pull Request
run: |
# Create a simpler PR body
PR_BODY="This PR adds the following wheel file to the wheels repository:\n- ${{ steps.build.outputs.WHEEL_FILENAME }}\n\nThis was automatically generated from the release workflow of ${{ github.repository }}."

# Properly escape the PR body for JSON
PR_BODY_ESCAPED=$(echo "$PR_BODY" | jq -Rs .)

# Create the PR
PR_RESPONSE=$(curl -X POST \
-H "Authorization: token ${{ secrets.CLONE_PRIVATE_REPOS_TOKEN }}" \
Expand All @@ -446,13 +434,13 @@ jobs:
\"head\": \"${WHEELS_BRANCH}\",
\"base\": \"main\"
}")

echo "API Response: $PR_RESPONSE"

# Extract PR URL and number
PR_URL=$(echo "$PR_RESPONSE" | jq -r '.html_url')
PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number')

# Add labels to the PR
if [ "$PR_NUMBER" != "null" ]; then
curl -X POST \
Expand All @@ -462,11 +450,11 @@ jobs:
-d '{
"labels": ["automated", "wheel"]
}'

echo "PR_URL=${PR_URL}" >> $GITHUB_ENV
echo "::notice::Pull Request created: ${PR_URL}"
else
echo "::error::Failed to create Pull Request"
echo "$PR_RESPONSE"
exit 1
fi
fi
Loading
Loading