From bbf4361e81b1e98bcc84a8eb58c0d6c2acac176c Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Tue, 4 Feb 2025 05:09:15 +1100 Subject: [PATCH] Improving CI (#438) * 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 --- .../actions/setup-runtimes-caching/action.yml | 123 ++++++++++++++++++ .github/workflows/dotnet-ci.yml | 105 +-------------- .github/workflows/dotnet-main.yml | 100 +------------- .github/workflows/dotnet-release.yml | 94 +------------ 4 files changed, 133 insertions(+), 289 deletions(-) create mode 100644 .github/actions/setup-runtimes-caching/action.yml diff --git a/.github/actions/setup-runtimes-caching/action.yml b/.github/actions/setup-runtimes-caching/action.yml new file mode 100644 index 00000000..ac50ec3a --- /dev/null +++ b/.github/actions/setup-runtimes-caching/action.yml @@ -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 diff --git a/.github/workflows/dotnet-ci.yml b/.github/workflows/dotnet-ci.yml index 64a21e07..0caf72a9 100644 --- a/.github/workflows/dotnet-ci.yml +++ b/.github/workflows/dotnet-ci.yml @@ -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 @@ -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 @@ -194,4 +96,3 @@ jobs: needs: build uses: ./.github/workflows/code-coverage.yml secrets: inherit - diff --git a/.github/workflows/dotnet-main.yml b/.github/workflows/dotnet-main.yml index d5117d9d..1420387d 100644 --- a/.github/workflows/dotnet-main.yml +++ b/.github/workflows/dotnet-main.yml @@ -12,11 +12,7 @@ jobs: build: strategy: matrix: - os: [ - windows-latest, - ubuntu-latest, - #, macos-latest - ] + os: [windows-latest, ubuntu-latest] fail-fast: false runs-on: "${{ matrix.os }}" env: @@ -24,97 +20,10 @@ jobs: 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 @@ -274,4 +183,3 @@ jobs: needs: build uses: ./.github/workflows/code-coverage.yml secrets: inherit - diff --git a/.github/workflows/dotnet-release.yml b/.github/workflows/dotnet-release.yml index e733e717..938443cd 100644 --- a/.github/workflows/dotnet-release.yml +++ b/.github/workflows/dotnet-release.yml @@ -24,97 +24,10 @@ jobs: 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.x - - - 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-release.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-release.yml" - name: Restore dependencies run: dotnet restore @@ -270,4 +183,3 @@ jobs: needs: build uses: ./.github/workflows/code-coverage.yml secrets: inherit -