Skip to content

Commit

Permalink
Improving CI (#438)
Browse files Browse the repository at this point in the history
* Using composite actions to ensure we are consistent across workflows

See https://docs.github.com/en/actions/sharing-automations/avoiding-duplication for info on reducing duplication

* action hash mistake

* Only doing dapr init on Linux
  • Loading branch information
aaronpowell authored Feb 3, 2025
1 parent 75fdbda commit bbf4361
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 289 deletions.
123 changes: 123 additions & 0 deletions .github/actions/setup-runtimes-caching/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: "Setup Runtimes, Caching, and Tools"
description: "Setup various runtimes, cache dependencies, and initialize tools"
inputs:
hash-file:
description: "The file to hash for caching"
required: true
runs:
using: "composite"
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install Uvicorn
shell: bash
run: |
python -m pip install --upgrade pip
pip install uvicorn
- uses: astral-sh/setup-uv@v5
name: Install uv

- uses: actions/setup-go@v5
name: Set up Go
with:
go-version: "^1.22.1"
cache-dependency-path: |
./**/go.sum
- uses: actions/setup-java@v4
name: Set up Java
with:
distribution: "microsoft"
java-version: "21"

- uses: actions/setup-node@v4
name: Set up Node.js
with:
node-version: "latest"

- uses: pnpm/action-setup@v4
name: Setup pnpm
with:
version: 9
run_install: false

- uses: denoland/setup-deno@v2
name: Setup Deno
with:
deno-version: v2.1.4

- uses: oven-sh/setup-bun@v2
name: Setup Bun
with:
bun-version: latest

- uses: dapr/setup-dapr@v2
name: Setup Dapr
with:
version: ${{ env.DAPR_VERSION }}

- uses: actions/cache@v4
name: Cache NuGet packages
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- uses: actions/cache@v4
name: Cache Java Docker images
with:
path: /var/lib/docker/image
key: ${{ runner.os }}-docker-${{ hashFiles('examples/java/CommunityToolkit.Aspire.Hosting.Java.Spring.Maven/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-
- name: Get NPM package root
id: npm-root
run: "echo path=$(npm root -g) >> $GITHUB_OUTPUT"
shell: bash

- uses: actions/cache@v4
name: Cache global npm packages
with:
path: ${{ steps.npm-root.outputs.path }}
key: ${{ runner.os }}-npm-${{ hashFiles('${{ inputs.hash-file }}') }}
restore-keys: |
${{ runner.os }}-npm-
- uses: Swatinem/rust-cache@v2
name: Cache Rust packages
with:
workspaces: "examples/rust/actix_api -> target"

- name: Setup .NET dev certs
shell: bash
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
dotnet tool update -g linux-dev-certs
dotnet linux-dev-certs install
- name: Setup Node projects
shell: bash
run: |
npm install -g @azure/static-web-apps-cli
cd examples/swa/CommunityToolkit.Aspire.StaticWebApps.WebApp
npm ci
- name: Init Dapr
shell: bash
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
dapr init --runtime-version=${{ env.DAPR_VERSION }}
dapr --version
105 changes: 3 additions & 102 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,107 +29,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Setup Runtimes, Caching, and Tools
uses: ./.github/actions/setup-runtimes-caching
with:
dotnet-version: |
8.0.x
9.0.x
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Uvicorn
run: |
python -m pip install --upgrade pip
pip install uvicorn
- uses: astral-sh/setup-uv@v5
name: Install uv
- uses: actions/setup-go@v5
name: Set up Go
with:
go-version: "^1.22.1"
cache-dependency-path: |
./**/go.sum
- uses: actions/setup-java@v4
name: Set up Java
with:
distribution: "microsoft"
java-version: "21"
- uses: actions/setup-node@v4
name: Set up Node.js
with:
node-version: "latest"

- uses: pnpm/action-setup@v4
name: Setup pnpm
with:
version: 9
run_install: false

- uses: denoland/setup-deno@v2
name: Setup Deno
with:
deno-version: v2.1.4

- uses: oven-sh/setup-bun@v2
name: Setup Bun
with:
bun-version: latest

- uses: dapr/setup-dapr@v2
name: Setup Dapr
with:
version: ${{ env.DAPR_VERSION }}

- uses: actions/cache@v4
name: Cache NuGet packages
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- uses: actions/cache@v4
name: Cache Java Docker images
with:
path: /var/lib/docker/image
key: ${{ runner.os }}-docker-${{ hashFiles('examples/java/CommunityToolkit.Aspire.Hosting.Java.Spring.Maven/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-
- name: Get NPM package root
id: npm-root
run: "echo path=$(npm root -g) >> $GITHUB_OUTPUT"
shell: bash

- uses: actions/cache@v4
name: Cache global npm packages
with:
path: ${{ steps.npm-root.outputs.path }}
key: ${{ runner.os }}-npm-${{ hashFiles('.github/workflows/dotnet-ci.yml') }}
restore-keys: |
${{ runner.os }}-npm-
- uses: Swatinem/rust-cache@v2
name: Cache Rust packages
with:
workspaces: "examples/rust/actix_api -> target"

- name: Setup .NET dev certs
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
dotnet tool update -g linux-dev-certs
dotnet linux-dev-certs install
- name: Setup Node projects
run: |
npm install -g @azure/static-web-apps-cli
cd examples/swa/CommunityToolkit.Aspire.StaticWebApps.WebApp
npm ci
- name: Init Dapr
run: |
dapr init --runtime-version=${{ env.DAPR_VERSION }}
dapr --version
hash-file: ".github/workflows/dotnet-ci.yml"

- name: Restore dependencies
run: dotnet restore
Expand All @@ -141,7 +44,6 @@ jobs:
- name: Publish NuGet package
run: dotnet pack --no-build -c ${{ env.DOTNET_CONFIGURATION }} -o ./nuget -p:VersionSuffix='alpha.${{ github.run_number }}'

## Only publish NuGet packages on Ubuntu, since we don't need to publish them on every OS
- name: Publish NuGet packages as artifacts
if: ${{ matrix.os == 'ubuntu-latest' && github.actor != 'dependabot[bot]' }}
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -194,4 +96,3 @@ jobs:
needs: build
uses: ./.github/workflows/code-coverage.yml
secrets: inherit

100 changes: 4 additions & 96 deletions .github/workflows/dotnet-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,109 +12,18 @@ jobs:
build:
strategy:
matrix:
os: [
windows-latest,
ubuntu-latest,
#, macos-latest
]
os: [windows-latest, ubuntu-latest]
fail-fast: false
runs-on: "${{ matrix.os }}"
env:
DOTNET_CONFIGURATION: Release

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ env.DEFAULT_DOTNET_VERSION }}
9.0.x
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Uvicorn
run: |
python -m pip install --upgrade pip
pip install uvicorn
- uses: astral-sh/setup-uv@v5
name: Install uv
- uses: actions/setup-go@v5
name: Set up Go
with:
go-version: "^1.22.1"
cache-dependency-path: |
./**/go.sum
- uses: actions/setup-java@v4
name: Set up Java
with:
distribution: "microsoft"
java-version: "21"
- uses: actions/setup-node@v4
name: Set up Node.js
with:
node-version: "latest"

- uses: pnpm/action-setup@v4
name: Setup pnpm
with:
version: 9
run_install: false

- uses: denoland/setup-deno@v2
name: Setup Deno
with:
deno-version: v2.1.4

- uses: oven-sh/setup-bun@v2
name: Setup Bun
- name: Setup Runtimes, Caching, and Tools
uses: ./.github/actions/setup-runtimes-caching
with:
bun-version: latest

- uses: actions/cache@v4
name: Cache NuGet packages
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- uses: actions/cache@v4
name: Cache Java Docker images
with:
path: /var/lib/docker/image
key: ${{ runner.os }}-docker-${{ hashFiles('examples/java/CommunityToolkit.Aspire.Hosting.Java.Spring.Maven/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-
- name: Get NPM package root
id: npm-root
run: "echo path=$(npm root -g) >> $GITHUB_OUTPUT"
shell: bash

- uses: actions/cache@v4
name: Cache global npm packages
with:
path: ${{ steps.npm-root.outputs.path }}
key: ${{ runner.os }}-npm-${{ hashFiles('.github/workflows/dotnet-main.yml') }}
restore-keys: |
${{ runner.os }}-npm-
- uses: Swatinem/rust-cache@v2
name: Cache Rust packages
with:
workspaces: "examples/rust/actix_api -> target"

- name: Setup .NET dev certs
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
dotnet tool update -g linux-dev-certs
dotnet linux-dev-certs install
- name: Setup Node projects
run: |
npm install -g @azure/static-web-apps-cli
cd examples/swa/CommunityToolkit.Aspire.StaticWebApps.WebApp
npm ci
hash-file: ".github/workflows/dotnet-main.yml"

- name: Restore dependencies
run: dotnet restore
Expand Down Expand Up @@ -274,4 +183,3 @@ jobs:
needs: build
uses: ./.github/workflows/code-coverage.yml
secrets: inherit

Loading

0 comments on commit bbf4361

Please sign in to comment.