Skip to content

Commit

Permalink
split the ci/cd into responsibility jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
nik-solcast committed Oct 24, 2024
1 parent 9b6f8be commit 6d78f0a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 49 deletions.
144 changes: 101 additions & 43 deletions .github/workflows/build-test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,107 @@ permissions:
packages: write

jobs:
build-test-publish:

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

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Copy README.md to the project folder
run: cp README.md src/Solcast/README.md

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build_artifacts
path: |
**/bin/Release/**
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build_artifacts

- name: Set API Key Environment Variable
run: echo "SOLCAST_API_KEY=${{ secrets.SOLCAST_API_KEY }}" >> $GITHUB_ENV

- name: Run tests
run: dotnet test --no-build --configuration Release

package:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Extract version from Git tag
run: |
CLEAN_VERSION="${GITHUB_REF##*/}" # Remove 'refs/tags/'
CLEAN_VERSION="${CLEAN_VERSION#v}" # Remove leading 'v'
echo "CLEAN_VERSION=$CLEAN_VERSION" >> $GITHUB_ENV # Set it as env variable
- name: Copy README.md to the project folder
run: cp README.md src/Solcast/README.md

- name: Restore dependencies
run: dotnet restore

- name: Pack NuGet Package with version from tag
run: dotnet pack src/Solcast/Solcast.csproj --configuration Release --output ./nupkg /p:PackageVersion=${{ env.CLEAN_VERSION }}

- name: Upload Package Artifact
uses: actions/upload-artifact@v3
with:
name: nuget_package
path: ./nupkg/*.nupkg

publish:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: package
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Copy README.md to the project folder
run: cp README.md src/Solcast/README.md

- name: Set API Key Environment Variable
run: echo "SOLCAST_API_KEY=${{ secrets.SOLCAST_API_KEY }}" >> $GITHUB_ENV

- name: Restore dependencies
run: dotnet restore

- name: Run tests
run: dotnet test

- name: Extract version from Git tag
if: startsWith(github.ref, 'refs/tags/') # Ensure this runs only for tags
run: |
CLEAN_VERSION="${GITHUB_REF##*/}" # Remove 'refs/tags/'
CLEAN_VERSION="${CLEAN_VERSION#v}" # Remove leading 'v'
echo "CLEAN_VERSION=$CLEAN_VERSION" >> $GITHUB_ENV # Set it as env variable
- name: Pack NuGet Package with version from tag
if: startsWith(github.ref, 'refs/tags/') # Only package on tag creation
run: dotnet pack src/Solcast/Solcast.csproj --configuration Release --output ./nupkg /p:PackageVersion=${{ env.CLEAN_VERSION }}

- name: Publish NuGet Package to GitHub Packages
if: startsWith(github.ref, 'refs/tags/') # Only publish on tag creation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: dotnet nuget push ./nupkg/*.nupkg --source "https://nuget.pkg.github.com/solcast/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}

- name: Publish NuGet Package to NuGet.org
if: startsWith(github.ref, 'refs/tags/')
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
- name: Download Package Artifact
uses: actions/download-artifact@v3
with:
name: nuget_package

- name: Publish NuGet Package to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: dotnet nuget push ./*.nupkg --source "https://nuget.pkg.github.com/solcast/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}

- name: Publish NuGet Package to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Docs

on:
workflow_run:
workflows: ["Build, Test, and Publish NuGet Package"] # Name of the build workflow
workflows: ["Build, Test, and Publish NuGet Package"]
types:
- completed

Expand All @@ -24,6 +23,7 @@ concurrency:

jobs:
deploy_docs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var liveClient = new LiveClient();
var response = await liveClient.GetRadiationAndWeather(
latitude: -33.856784,
longitude: 151.215297,
output_parameters: ["air_temp", "dni", "ghi"]
outputParameters: ["air_temp", "dni", "ghi"]
format: "csv"
);

Expand All @@ -81,7 +81,7 @@ var forecastClient = new ForecastClient();
var response = await forecastClient.GetForecast(
latitude: -33.856784,
longitude: 151.215297,
output_parameters: ["air_temp", "dni", "ghi"]
outputParameters: ["air_temp", "dni", "ghi"]
);
```

Expand Down
2 changes: 1 addition & 1 deletion docs/forecast.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dni,ghi,air_temp,period_end,period
## API Parameters
- **latitude**: Latitude of the location in decimal degrees (north is positive).
- **longitude**: Longitude of the location in decimal degrees (east is positive).
- **output_parameters**: An array of parameters to return, such as `dni`, `ghi`, `air_temp`.
- **outputParameters**: An array of parameters to return, such as `dni`, `ghi`, `air_temp`.
- **format**: The format of the output (e.g., "json", "csv").

For more information about the forecast data API, visit the [Solcast API Docs](https://docs.solcast.com.au/#80627973-4183-4ebc-8a3d-1b2324fd1ed1).
Expand Down
2 changes: 1 addition & 1 deletion docs/live.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dni,ghi,air_temp,period_end,period
## API Parameters
- **latitude**: Latitude of the location in decimal degrees (north is positive).
- **longitude**: Longitude of the location in decimal degrees (east is positive).
- **output_parameters**: An array of parameters to return, such as `dni`, `ghi`, `air_temp`.
- **outputParameters**: An array of parameters to return, such as `dni`, `ghi`, `air_temp`.
- **format**: The format of the output (e.g., "json", "csv").

---
Expand Down

0 comments on commit 6d78f0a

Please sign in to comment.