Skip to content

Commit

Permalink
Merge branch 'main' into alwhr/move-contracts-to-measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
awha86 committed Dec 6, 2024
2 parents 23f141b + 1153a6c commit aab215f
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 5 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2020 Energinet DataHub A/S
#
# Licensed under the Apache License, Version 2.0 (the "License2");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: CD

on:
workflow_dispatch: {}
push:
branches:
- main

jobs:
#
# Detect changes to start relevant jobs
#

changes:
uses: ./.github/workflows/detect-changes.yml

#
# CD Databricks
#

electrical_heating:
needs: changes
if: ${{ needs.changes.outputs.electrical_heating == 'true' }}
uses: Energinet-DataHub/.github/.github/workflows/promote-prerelease.yml@v14
with:
release_name_prefix: electrical_heating

#
# Dispatch deployment request
#

dispatch_deploment_event:
if: ${{ always() && !cancelled() && !failure() && needs.changes.outputs.electrical_heating == 'true' }}
runs-on: ubuntu-latest
needs: [
changes,
electrical_heating
]
steps:
- run: echo "${{ toJSON(needs) }}"

- name: Find associated pull request
uses: Energinet-DataHub/.github/.github/actions/find-related-pr-number@v14
id: find_pull_request

- uses: Energinet-DataHub/.github/.github/actions/github-create-token@v14
name: Generate Github token
id: generate_token
with:
app_id: ${{ vars.dh3serviceaccount_appid }}
private_key: ${{ secrets.dh3serviceaccount_privatekey }}

- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate_token.outputs.token }}
repository: ${{ vars.environment_repository_path }}
event-type: measurements-deployment-request-domain
# yamllint disable-line rule:quoted-strings
client-payload: '{"pr_number": "${{ steps.find_pull_request.outputs.pull_request_number }}", "electrical_heating": "${{ needs.changes.outputs.electrical_heating }}"}'

#
# Send notification to teams channel if deployment dispatch failed
#

dispatch_failed:
needs:
[
electrical_heating,
dispatch_deploment_event
]
if: |
always() &&
contains(needs.*.result, 'failure')
uses: Energinet-DataHub/.github/.github/workflows/notify-team.yml@v14
with:
team_name: Mandalorian
subject: "Deployment dispatch failed: Measurements"
secrets: inherit
36 changes: 36 additions & 0 deletions .github/workflows/ci-electrical-heating.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI Electrical Heating

on:
workflow_call:

jobs:
databricks_ci_build:
uses: Energinet-DataHub/.github/.github/workflows/databricks-build-prerelease.yml@v14
with:
python_version: 3.11.7
architecture: x64
wheel_working_directory: ./source/electrical_heating
prerelease_prefix: electrical_heating

mypy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Run pip install and mypy check of files in package
shell: bash
run: |
pip install --upgrade pip
pip install mypy types-python-dateutil
mypy ./source/electrical_heating --disallow-untyped-defs --ignore-missing-imports
black_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: --check --diff
src: ./source/electrical_heating
36 changes: 34 additions & 2 deletions .github/workflows/ci-orchestrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,43 @@ concurrency:

jobs:

#
# License and Markdown Check.
#
ci_base:
uses: Energinet-DataHub/.github/.github/workflows/ci-base.yml@v14
with:
skip_license_check: true
secrets:
dh3serviceaccount_privatekey: ${{ secrets.dh3serviceaccount_privatekey }}

changes:
uses: ./.github/workflows/detect-changes.yml

ci_electrical_heating:
needs: [changes]
if: ${{ needs.changes.outputs.electrical_heating == 'true' }}
uses: ./.github/workflows/ci-electrical-heating.yml

#
# Branch policy status check
#

allow_merge_ci_orchestrator:
runs-on: ubuntu-latest
needs:
[
changes,
ci_base,
ci_electrical_heating,
]
if: |
always()
steps:
- name: Verify if merge is allowed
run: |
echo "Success"
echo "${{ toJSON(needs) }}"
if [[ ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} = true ]]; then
echo "Failed"
exit 1
fi
36 changes: 36 additions & 0 deletions .github/workflows/detect-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Detect changes

# DESCRIPTION:
# This workflow will determine which categories of jobs should be executed,
# based on detected changes.
# It should be used by the 'ci-orchestrator.yml' and 'cd.yml' to ensure they both use
# the same path's to detect changes.

on:
workflow_call:
outputs:
electrical_heating:
value: ${{ jobs.changes.outputs.electrical_heating }}

jobs:
changes:
name: Determine relevant jobs
runs-on: ubuntu-latest
# Set job outputs to values from filter step
outputs:
electrical_heating: ${{ steps.filter.outputs.electrical_heating }}
steps:
# For pull requests it's not necessary to checkout the code because GitHub REST API is used to determine changes
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Detect file changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
electrical_heating:
- 'source/electrical_heating/**'
- '.github/workflows/ci-electrical-heating.yml'
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

def execute() -> None:
def execute() -> None:
"""
Entry point for the electrical heating job.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses import dataclass


@dataclass
class ElectricalHeatingArgs:
"""
Args for the electrical heating job.
"""

electrical_heating_id: str
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import argparse
import sys
import configargparse
from argparse import Namespace
from telemetry_logging import Logger, logging_configuration

from .electrical_heating_args import ElectricalHeatingArgs


def parse_command_line_arguments() -> Namespace:
return _parse_args_or_throw(sys.argv[1:])


def parse_job_arguments(
job_args: Namespace,
) -> ElectricalHeatingArgs:
logger = Logger(__name__)
logger.info(f"Command line arguments: {repr(job_args)}")

with logging_configuration.start_span("electrical_heating.parse_job_arguments"):

electrical_heating_args = ElectricalHeatingArgs(
electrical_heating_id=job_args.electrical_heating_id,
)

return electrical_heating_args


def _parse_args_or_throw(command_line_args: list[str]) -> argparse.Namespace:
p = configargparse.ArgParser(
description="Execute electrical heating calculation",
formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
)

# Run parameters
p.add_argument("--electrical-heating-id", type=str, required=True)

args, unknown_args = p.parse_known_args(args=command_line_args)
if len(unknown_args):
unknown_args_text = ", ".join(unknown_args)
raise Exception(f"Unknown args: {unknown_args_text}")

return args
2 changes: 1 addition & 1 deletion source/electrical_heating/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
entry_points={
"console_scripts": [
"execute = electrical_heating_job.entry_point:execute",
]
]
},
)

0 comments on commit aab215f

Please sign in to comment.