From 96c29e3ff3e5d4f0632ba81ab5907c56678eebc4 Mon Sep 17 00:00:00 2001 From: Romeo Dumitrescu Date: Sat, 15 Jun 2024 11:04:28 +0300 Subject: [PATCH] devops: rework CI and CD to use source change detection --- .github/workflows/main.yaml | 43 +++++++++++++++++++++++-------------- .github/workflows/pr.yaml | 24 --------------------- 2 files changed, 27 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/pr.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 4de2ae3..7908c89 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,47 +1,61 @@ -name: Main +name: Main Workflow on: push: branches: - '**' # Matches all branches + pull_request: jobs: ci: name: CI runs-on: ubuntu-latest + outputs: + src_changed: ${{ steps.src_changed.outputs.changes }} steps: - name: checkout uses: actions/checkout@v4 with: - fetch-depth: 1 + fetch-depth: 0 + + - name: src - identify source changes + id: src_changed + uses: dorny/paths-filter@v3 + with: + base: ${{ github.ref }} + filters: | + src: + - 'src/**' + solution: + - 'ES.FX.sln' + build: + - 'Directory.Build.props' - name: build uses: ./.github/actions/build + if: steps.src_changed.outputs.src == 'true' with: configuration: Debug useVersioning: false - name: test + if: steps.src_changed.outputs.src == 'true' uses: ./.github/actions/test cd: name: CD - needs: ci runs-on: ubuntu-latest + needs: ci if: > - ( - contains(toJson(github.event.commits), 'src/') || - contains(toJson(github.event.commits), 'ES.FX.sln') || - contains(toJson(github.event.commits), 'Directory.Build.props') - ) && ( - github.ref == 'refs/heads/main' || + needs.ci.outputs.src_changed == 'true' && + github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.event == 'push' && + (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/release/') || - startsWith(github.ref, 'refs/heads/hotfix/') - ) - + startsWith(github.ref, 'refs/heads/hotfix/')) steps: - name: checkout uses: actions/checkout@v4 @@ -79,12 +93,9 @@ jobs: - name: dotnet nuget add source shell: bash run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/emberstack/index.json" - - + - name: dotnet nuget push run: | for pkg in .artifacts/nuget/*.nupkg; do dotnet nuget push "$pkg" --source "github" --api-key ${{ secrets.ES_GITHUB_PAT }} done - - diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml deleted file mode 100644 index 6781a65..0000000 --- a/.github/workflows/pr.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: Pull Request - -on: - pull_request: - -jobs: - ci: - name: CI - runs-on: ubuntu-latest - steps: - - - name: checkout - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: build - uses: ./.github/actions/build - with: - configuration: Debug - useVersioning: false - - - name: test - uses: ./.github/actions/test \ No newline at end of file