From b46c6e41041f6152466f83eb5b7b14429bcbd8b4 Mon Sep 17 00:00:00 2001 From: "Omer Y. Bayraktar" Date: Fri, 25 Oct 2024 11:19:59 +0300 Subject: [PATCH] workflow patches --- .github/workflows/auto-release.yml | 177 +++++++++++++++++++++++++++++ .github/workflows/changelog.yml | 13 +-- .github/workflows/check.yml | 15 ++- 3 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/auto-release.yml diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..c309f9e --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,177 @@ +name: Auto Release + +on: + push: + branches: + - master + paths-ignore: + - '**/*.md' + - '**/*.yml' + - '**/*.hbs' + +permissions: + contents: write + packages: write + +jobs: + build-and-release: + runs-on: windows-latest + + env: + EnablePreRelease: 'false' # true or false to enable pre-release like 1.0.0.0-pre + IsPreRelease: 'false' #leave false + EndProcess: 'false' #leave false + VERSION: '' #leave empty + ASSEMBLY_VERSION: '' #leave empty + FILE_VERSION: '' #leave empty + new_tag: '' #leave empty + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract version information + id: version + shell: bash + run: | + fileContent=$(cat ./*.csproj) + + versionLine=$(echo "$fileContent" | grep -oEm1 "()(.*?)(<\/Version>)" | sed -E 's/<\/?Version>//g') + VERSION=$(echo "$versionLine" | awk '{$1=$1};1') + + versionLine=$(echo "$fileContent" | grep -oEm1 "()(.*?)(<\/AssemblyVersion>)" | sed -E 's/<\/?AssemblyVersion>//g') + ASSEMBLY_VERSION=$(echo "$versionLine" | awk '{$1=$1};1') + + versionLine=$(echo "$fileContent" | grep -oEm1 "()(.*?)(<\/FileVersion>)" | sed -E 's/<\/?FileVersion>//g') + FILE_VERSION=$(echo "$versionLine" | awk '{$1=$1};1') + + echo "ASSEMBLY_VERSION=$ASSEMBLY_VERSION" >> $GITHUB_ENV + echo "FILE_VERSION=$FILE_VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV + + echo "ASSEMBLY_VERSION: $ASSEMBLY_VERSION" + echo "FILE_VERSION: $FILE_VERSION" + echo "VERSION: $VERSION" + + - name: Check if tag exists + id: tag_check + shell: bash + run: | + git fetch --all + + if [[ "${{ env.VERSION }}" == "0.0.0" ]]; then + echo "EndProcess=true" >> $GITHUB_ENV + fi + + if git rev-parse -q --verify "refs/tags/v${{ env.VERSION }}" >/dev/null; then + if git rev-parse -q --verify "refs/tags/v${{ env.ASSEMBLY_VERSION }}-pre" >/dev/null; then + echo "EndProcess=true" >> $GITHUB_ENV + else + if [[ "${{ env.EnablePreRelease }}" == "true" ]]; then + echo "new_tag=v${{ env.ASSEMBLY_VERSION }}-pre" >> $GITHUB_ENV + echo "IsPreRelease=true" >> $GITHUB_ENV + else + echo "new_tag=v${{ env.ASSEMBLY_VERSION }}" >> $GITHUB_ENV + echo "EndProcess=true" >> $GITHUB_ENV + fi + fi + else + echo "new_tag=v${{ env.VERSION }}" >> $GITHUB_ENV + echo "IsPreRelease=false" >> $GITHUB_ENV + fi + + - name: Create new tag + if: env.EndProcess == 'false' + shell: bash + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + new_tag="${{ env.new_tag }}" + git tag $new_tag + git push origin $new_tag + + - name: Set up Node.js + if: env.EndProcess == 'false' + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install auto-changelog + if: env.EndProcess == 'false' + run: npm install -g auto-changelog + + - name: Generate Changelog + if: env.EndProcess == 'false' + run: | + git fetch --tags + auto-changelog --template .github/changelog.hbs --hide-credit --commit-limit false --ignore-commit-pattern '(\.md|\.yml|\.hbs)' --tag-pattern '(.*)' --output RELEASE.md --backfill-limit false --starting-version ${{ env.new_tag }} + + - name: Create Release for new tag + if: env.EndProcess == 'false' + id: create_release + uses: actions/create-release@v1 + with: + tag_name: '${{ env.new_tag }}' + release_name: '${{ env.new_tag }}' + draft: false + prerelease: false + body_path: RELEASE.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup .NET + if: env.EndProcess == 'false' + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Restore dependencies + if: env.EndProcess == 'false' + run: dotnet restore + + - name: Build for x64 + if: env.EndProcess == 'false' + run: dotnet publish --configuration Release --runtime win-x64 --self-contained false --output ./bin/Publish/win-x64 + + - name: Zip x64 + if: env.EndProcess == 'false' + run: Compress-Archive -Path "./bin/Publish/win-x64/*" -DestinationPath "./bin/Publish/win-x64.zip" + + - name: Upload x64 Release Asset + if: env.EndProcess == 'false' + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./bin/Publish/win-x64.zip + asset_name: win-x64.zip + asset_content_type: application/zip + + - name: Build for x64 + if: env.EndProcess == 'false' + run: dotnet publish --configuration Release --runtime win-x64 --self-contained false --output ./bin/Publish/win-x64 + + - name: Zip x64 + if: env.EndProcess == 'false' + run: Compress-Archive -Path "./bin/Publish/win-x64/*" -DestinationPath "./bin/Publish/win-x64.zip" + + - name: Upload x64 Release Asset + if: env.EndProcess == 'false' + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./bin/Publish/win-x64.zip + asset_name: win-x64.zip + asset_content_type: application/zip + + - name: Run Changelog Workflow + uses: peter-evans/repository-dispatch@v3 + with: + repository: ${{ github.repository }} + token: ${{ secrets.GITHUB_TOKEN }} + event-type: generate-changelog diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 4516b28..e1376b9 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -1,15 +1,8 @@ -name: Generate and Commit Changelog +name: Generate Changelog on: - push: - branches: ['main'] - paths-ignore: - - '**/*.md' - - '**/*.yml' - - '**/*.hbs' - workflow_dispatch: repository_dispatch: - types: [build-complete] + types: [generate-changelog] permissions: contents: write @@ -27,7 +20,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: '18' + node-version: "18" - name: Install auto-changelog run: npm install -g auto-changelog diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c90f6b2..5732500 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -4,6 +4,11 @@ name: .NET on: + push: + paths-ignore: + - '**/*.md' + - '**/*.yml' + - '**/*.hbs' pull_request: permissions: @@ -20,7 +25,15 @@ jobs: dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore + - name: Build run: dotnet build --no-restore - - name: Test + + - name: Test Code run: dotnet test --no-build --verbosity normal + + - name: Install CSharpier + run: dotnet tool install -g csharpier + + - name: Run CSharpier + run: dotnet csharpier . --check