diff --git a/.github/workflows/build-and-unit-test.yml b/.github/workflows/build-and-unit-test.yml new file mode 100644 index 0000000..56fd82b --- /dev/null +++ b/.github/workflows/build-and-unit-test.yml @@ -0,0 +1,19 @@ +name: Build and test + +on: + push: + branches: [ '**', '!main' ] + pull_request: + branches: [ '**' ] + +jobs: + build-and-unit-test: + uses: ./.github/workflows/reusable-build-and-unit-test.yml + cleanup-workflow-run-logs: + uses: ./.github/workflows/reusable-github-workflow-run-cleanup.yml + needs: build-and-unit-test + permissions: + actions: write + with: + days_old: "0" + runs_to_keep: "2" diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml new file mode 100644 index 0000000..7a726e8 --- /dev/null +++ b/.github/workflows/github-release.yml @@ -0,0 +1,54 @@ +name: Create github release + +on: + push: + branches: [ 'main' ] + +jobs: + + build-and-unit-test: + uses: ./.github/workflows/reusable-build-and-unit-test.yml + + publish: + runs-on: ${{ matrix.operating-system }} + needs: build-and-unit-test + permissions: + contents: write + + strategy: + matrix: + operating-system: [ubuntu-latest] + + steps: + - name: Download solution artifact + uses: actions/download-artifact@main + with: + name: Solution artifact + - name: Publish + run: dotnet publish --configuration Release -p:UseAppHost=false --no-build --verbosity normal --output ./dist ./src/FileSorter.Console/FileSorter.Console.csproj + + - name: Archive Release + uses: thedoctor0/zip-release@0.7.5 + with: + type: 'zip' + filename: file-sorter-v0.${{ github.run_number }}.0-beta.zip + exclusions: '*.git* /*node_modules/* .editorconfig' + path: dist + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: file-sorter-v0.${{ github.run_number }}.0-beta.zip + tag_name: v0.${{ github.run_number }}.0-beta + prerelease: true + draft: true + generate_release_notes: true + + cleanup-workflow-run-logs: + uses: ./.github/workflows/reusable-github-workflow-run-cleanup.yml + needs: publish + permissions: + actions: write + with: + days_old: "0" + runs_to_keep: "2" diff --git a/.github/workflows/dotnet.yml b/.github/workflows/reusable-build-and-unit-test.yml similarity index 61% rename from .github/workflows/dotnet.yml rename to .github/workflows/reusable-build-and-unit-test.yml index 00b0b83..e901b81 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/reusable-build-and-unit-test.yml @@ -1,10 +1,7 @@ -name: .NET +name: Build and test on: - push: - branches: [ "**" ] - pull_request: - branches: [ "**" ] + workflow_call: jobs: build: @@ -15,7 +12,8 @@ jobs: operating-system: [ubuntu-latest] steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 with: @@ -24,11 +22,11 @@ jobs: run: dotnet restore - name: Build run: dotnet build --no-restore --configuration Release - - name: Upload build artifact + - name: Upload solution artifact uses: actions/upload-artifact@main with: - name: Build artifact - path: ./test/FileSorter.UnitTest/bin/Release/ + name: Solution artifact + path: . if-no-files-found: error test: @@ -40,11 +38,9 @@ jobs: operating-system: [ubuntu-latest, windows-latest, macos-latest] steps: - - name: Download build artifact + - name: Download solution artifact uses: actions/download-artifact@main with: - name: Build artifact - - name: Test build artifact download - run: ls -R - - name: Test - run: dotnet test */FileSorter.UnitTest.dll --no-build --verbosity normal + name: Solution artifact + - name: Unit Test + run: dotnet test ./test/FileSorter.UnitTest/bin/Release/*/FileSorter.UnitTest.dll --no-build --verbosity normal diff --git a/.github/workflows/reusable-github-workflow-run-cleanup.yml b/.github/workflows/reusable-github-workflow-run-cleanup.yml new file mode 100644 index 0000000..5870eb3 --- /dev/null +++ b/.github/workflows/reusable-github-workflow-run-cleanup.yml @@ -0,0 +1,27 @@ +name: Clean up workflow runs + +on: + workflow_call: + inputs: + days_old: + description: "The amount of days old to delete" + type: string + default: "0" + required: false + runs_to_keep: + description: "The amount of latest workflows runs to keep" + type: string + default: "2" + required: false + +jobs: + clean-logs: + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - uses: igorjs/gh-actions-clean-workflow@v4 + with: + days_old: "0" + runs_to_keep: "2" +