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/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Docker Build

on:
workflow_call:
inputs:
push_to_registry:
type: boolean
default: false
required: false
version:
type: string
required: true
branch:
type: string
required: true
platforms:
type: string
default: 'linux/amd64'
required: false
secrets:
AWS_ACCOUNT_NUMBER:
required: true
AWS_ROLE:
required: true
AWS_REGION:
required: true

permissions:
contents: read
packages: write
id-token: write

jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_NUMBER }}:role/${{ secrets.AWS_ROLE }}
role-session-name: updateimage
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ secrets.AWS_ACCOUNT_NUMBER }}

- name: Set Docker tags based on branch
id: set_tags
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
if [[ "${{ inputs.branch }}" == "main" ]]; then
echo "TAGS=$ECR_REGISTRY/hydroshift:latest,$ECR_REGISTRY/hydroshift:${{ inputs.version }}" >> $GITHUB_OUTPUT
else
echo "TAGS=$ECR_REGISTRY/hydroshift:pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
fi

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push_to_registry }}
tags: ${{ steps.set_tags.outputs.TAGS }}
cache-from: type=gha
cache-to: type=gha,mode=max
44 changes: 44 additions & 0 deletions .github/workflows/get-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Get Version

on:
workflow_call:
outputs:
version:
description: "The version string extracted from hydroshift.__version__"
value: ${{ jobs.get-version.outputs.version }}
is_new_version:
description: "Whether this version is new (not previously tagged)"
value: ${{ jobs.get-version.outputs.is_new_version }}

jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
is_new_version: ${{ steps.check_tag.outputs.IS_NEW_VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Extract version from hydroshift
id: get_version
run: |
VERSION=$(python -c "import hydroshift; print(hydroshift.__version__)")
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"

- name: Check if version exists as tag
id: check_tag
run: |
if git tag | grep -q "v${{ steps.get_version.outputs.VERSION }}"; then
echo "Version ${{ steps.get_version.outputs.VERSION }} already exists as a tag."
echo "IS_NEW_VERSION=false" >> "$GITHUB_OUTPUT"
else
echo "Version ${{ steps.get_version.outputs.VERSION }} does not exist as a tag."
echo "IS_NEW_VERSION=true" >> "$GITHUB_OUTPUT"
fi
47 changes: 47 additions & 0 deletions .github/workflows/main-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Main Branch Push

on:
push:
branches: [ "main" ]
paths:
- 'hydroshift/**'
- 'tests/**'
- '.devcontainer/Dockerfile'
- '.dockerignore'
- '.github/workflows/**'
- 'pyproject.toml'
workflow_dispatch:

permissions:
contents: write
packages: write
id-token: write

jobs:
get-version:
name: Extract Package Version
uses: ./.github/workflows/get-version.yaml

check-version-exists:
name: Verify Version is New
needs: get-version
runs-on: ubuntu-latest
steps:
- name: Fail if version already exists
if: needs.get-version.outputs.is_new_version != 'true'
run: |
echo "::error::ERROR: Version ${{ needs.get-version.outputs.version }} already exists as a tag."
echo "::error::Please update the version in hydroshift/__init__.py before releasing to main."
exit 1
- name: Version check passed
run: echo "Version ${{ needs.get-version.outputs.version }} is new. Proceeding with release."

docker-build-push:
name: Build and Push Docker Image
needs: [get-version, check-version-exists]
uses: ./.github/workflows/docker-build.yaml
with:
push_to_registry: true
version: ${{ needs.get-version.outputs.version }}
branch: 'main'
platforms: 'linux/amd64'
33 changes: 33 additions & 0 deletions .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PR Checks

on:
pull_request:
branches: [ "main" ]
paths:
- 'hydroshift/**'
- 'tests/**'
- '/.devcontainer/Dockerfile'
- '.dockerignore'
- '.github/workflows/**'
- 'pyproject.toml'

permissions:
contents: read
packages: write
id-token: write

jobs:
get-version:
name: Extract Package Version
uses: ./.github/workflows/get-version.yaml

docker-build-test:
name: Test Docker Build
needs: get-version
uses: ./.github/workflows/docker-build.yaml
with:
push_to_registry: false
version: ${{ needs.get-version.outputs.version }}
branch: ${{ github.base_ref }}
platforms: 'linux/amd64'
secrets: inherit
File renamed without changes.
1 change: 1 addition & 0 deletions hydroshift/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
1 change: 1 addition & 0 deletions hydroshift/_pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from hydroshift._pages.changepoint import changepoint
from hydroshift._pages.homepage import homepage
from hydroshift._pages.summary import summary
Loading