Skip to content

Commit 6de79ab

Browse files
committed
Add GHA
1 parent e66d8ea commit 6de79ab

File tree

9 files changed

+492
-184
lines changed

9 files changed

+492
-184
lines changed

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude = .venv,__pycache__,.pytest_cache,.git,.tox,.eggs,*.egg,*.egg-info,*.egg-info/*
3+
max-line-length = 90
4+
ignore = I201, I100, I101, W503

.github/workflows/ci.yaml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
test-and-build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install flake8 flake8-import-order
28+
pip install -e .
29+
30+
- name: Run flake8
31+
run: |
32+
flake8 . --count --statistics \
33+
--select=E,W,F,I \
34+
--show-source
35+
36+
- name: Run pytest
37+
run: |
38+
pytest tests/
39+
40+
- name: Login to GitHub Container Registry
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Extract branch name
48+
shell: bash
49+
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
50+
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v5
53+
with:
54+
context: .
55+
push: true
56+
tags: ghcr.io/${{ github.repository_owner }}/downscaled-climate-data:${{ env.BRANCH_NAME }}

downscaled_climate_data/assets/loca2.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import requests
2-
from dagster import asset, Config, AssetExecutionContext
1+
from dagster import AssetExecutionContext, Config, asset
32
from dagster_aws.s3 import S3Resource
43

4+
import requests
5+
56

67
class Loca2Config(Config):
78
bucket: str = "loca2-data"
89
s3_key: str
9-
url: str = "https://cirrus.ucsd.edu/~pierce/LOCA2/CONUS_regions_split/ACCESS-CM2/cent/0p0625deg/r2i1p1f1/historical/tasmax/tasmax.ACCESS-CM2.historical.r2i1p1f1.1950-2014.LOCA_16thdeg_v20220413.cent.nc"
10+
url: str = "https://cirrus.ucsd.edu/~pierce/LOCA2/CONUS_regions_split/ACCESS-CM2/cent/0p0625deg/r2i1p1f1/historical/tasmax/tasmax.ACCESS-CM2.historical.r2i1p1f1.1950-2014.LOCA_16thdeg_v20220413.cent.nc" # NOQA E501
1011

1112

1213
@asset(
1314
name="RawLOCA2",
1415
description="Raw LOCA2 data downloaded from the web",
1516
)
16-
def loca2_raw(context: AssetExecutionContext, config: Loca2Config, s3: S3Resource) -> None:
17+
def loca2_raw(context: AssetExecutionContext,
18+
config: Loca2Config,
19+
s3: S3Resource) -> None:
1720

1821
with requests.get(config.url, stream=True) as response:
1922
# Raise an exception for bad HTTP responses
@@ -27,5 +30,3 @@ def loca2_raw(context: AssetExecutionContext, config: Loca2Config, s3: S3Resourc
2730
)
2831

2932
context.log.info(f"Downloading data to {config.s3_key}")
30-
31-

downscaled_climate_data/definitions.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from typing import Dict
2-
3-
from dagster import Definitions, load_assets_from_modules, define_asset_job, op, EnvVar
4-
5-
from downscaled_climate_data import assets # noqa: TID252
6-
from downscaled_climate_data.sensors.loca2_sensor import loca2_sensor, Loca2Datasets, Loca2Models
1+
from dagster import Definitions, EnvVar
72
from dagster_aws.s3 import S3Resource
8-
from downscaled_climate_data.assets.loca2 import loca2_raw
93

4+
from downscaled_climate_data.assets.loca2 import loca2_raw
5+
from downscaled_climate_data.sensors.loca2_models import Loca2Models
6+
from downscaled_climate_data.sensors.loca2_sensor import (loca2_sensor, Loca2Datasets)
107

118
defs = Definitions(
129
assets=[loca2_raw],

0 commit comments

Comments
 (0)