diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..7c9b33a --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,95 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the main branch +on: + push: + branches: + - main + tags: + - v* + pull_request: + # The branches below must be a subset of the branches above + branches: + - main + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: windows-latest + + # Any commit that contains [build] will now trigger these jobs, everything else will be skipped. + # if: "contains(github.event.head_commit.message, '[build]')" + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Version + if: startsWith(github.ref, 'refs/tags/v') + shell: pwsh + run: | + if (startsWith(github.ref, 'refs/tags/v')){ + $BuildVersion=${{ github.ref_name }}.Substring(1); + } + else{ + $BuildVersion=${{ github.ref_name }}; + } + echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV + echo ${{env.BuildVersion}} + + - name: Build Test + shell: cmd + run: | + .\Veil.Test\BuildAllTargets.cmd + + - name: Build NuGet + if: startsWith(github.ref, 'refs/tags/v') + shell: pwsh + run: | + # github的内置版本有Bug,此行必须添加,否则无法获得内容 + git fetch --depth=1 origin +refs/tags/*:refs/tags/* + + $releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10) + $content = [System.IO.File]::ReadAllText("Veil.NuGet\Musa.Veil.nuspec") + + $releaseNotesToken = '$releaseNotes$' + $releaseNotesIndex = $content.IndexOf($releaseNotesToken) + + if($releaseNotesIndex -ne -1) + { + echo $content.Substring(0, $releaseNotesIndex) | out-file "Veil.NuGet\Musa.Veil-New.nuspec" -NoNewline + echo $releaseNotes | out-file "Veil.NuGet\Musa.Veil-New.nuspec" -Append + echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "Veil.NuGet\Musa.Veil-New.nuspec" -NoNewline -Append + } + + - name: Package + if: startsWith(github.ref, 'refs/tags/v') + shell: cmd + run: | + if "${{env.BuildVersion}}" NEQ "" ( + NuGet pack .\Veil.NuGet\Musa.Veil-New.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA% + ) + if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL% + + - name: Publish NuGet + if: startsWith(github.ref, 'refs/tags/v') + shell: cmd + run: | + NuGet push Musa.Veil.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json + if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL% + + - name: Publish + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/v') + with: + files: | + *.nupkg \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index ae034fc..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Build - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the main branch -on: - push: - branches: [ main ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ main ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - Build: - # The type of runner that the job will run on - runs-on: windows-2022 - - # Any commit that contains [build] will now trigger these jobs, everything else will be skipped. - # if: "contains(github.event.head_commit.message, '[build]')" - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - with: - submodules: false - - #- name: Enable X86 and ARM build support - # working-directory: ${{github.workspace}} - # shell: pwsh - # run: | - # .\.github\workflows\EnableX86AndARM.ps1 - - - name: Build - working-directory: ${{github.workspace}} - shell: cmd - run: | - .\Veil.Test\BuildAllTargets.cmd diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index 447f055..0000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,91 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Publish - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - tags: - - v* - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - Build: - # The type of runner that the job will run on - runs-on: Windows-2022 - - # Any commit that contains [build] will now trigger these jobs, everything else will be skipped. - # if: "contains(github.event.head_commit.message, '[publish]')" - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - with: - submodules: false - - #- name: Enable X86 and ARM build support - # working-directory: ${{github.workspace}} - # shell: pwsh - # run: | - # .\.github\workflows\EnableX86AndARM.ps1 - - - name: Build - working-directory: ${{github.workspace}} - shell: cmd - run: | - .\Veil.Test\BuildAllTargets.cmd - - - name: Build NuGet - if: contains(github.ref, 'tags/') - working-directory: ${{github.workspace}} - shell: pwsh - run: | - if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase")) - { - $BuildVersion = $env:GITHUB_REF.Remove(0, 11); - echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV - - # github的内置版本有Bug,此行必须添加,否则无法获得内容 - git fetch --depth=1 origin +refs/tags/*:refs/tags/* - - $releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10) - $content = [System.IO.File]::ReadAllText("Veil.NuGet\Musa.Veil.nuspec") - - $releaseNotesToken = '$releaseNotes$' - $releaseNotesIndex = $content.IndexOf($releaseNotesToken) - - if($releaseNotesIndex -ne -1) - { - echo $content.Substring(0, $releaseNotesIndex) | out-file "Veil.NuGet\Musa.Veil-New.nuspec" -NoNewline - echo $releaseNotes | out-file "Veil.NuGet\Musa.Veil-New.nuspec" -Append - echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "Veil.NuGet\Musa.Veil-New.nuspec" -NoNewline -Append - } - } - - - name: Pack a NuGet - if: contains(github.ref, 'tags/') - working-directory: ${{github.workspace}} - shell: cmd - run: | - if "${{env.BuildVersion}}" NEQ "" ( - NuGet pack .\Veil.NuGet\Musa.Veil-New.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA% - ) - if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL% - - - name: Publish a NuGet package - if: contains(github.ref, 'tags/') - working-directory: ${{github.workspace}} - shell: cmd - run: | - NuGet push Musa.Veil.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json - if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL% - - - name: Publish a version - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') - with: - files: | - *.nupkg