|
| 1 | +name: Release JobAgent |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # branches: |
| 6 | + # - "**" |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build ${{ matrix.os }} / ${{ matrix.runtime }} |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + outputs: |
| 20 | + version: ${{ steps.set_version.outputs.version }} # 🚀 expouse version |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - os: ubuntu-latest |
| 25 | + runtime: linux-x64 |
| 26 | + - os: ubuntu-latest |
| 27 | + runtime: linux-arm64 |
| 28 | + - os: windows-latest |
| 29 | + runtime: win-x64 |
| 30 | + - os: macos-latest |
| 31 | + runtime: osx-x64 |
| 32 | + steps: |
| 33 | + - name: Set Version |
| 34 | + id: set_version |
| 35 | + shell: bash |
| 36 | + env: |
| 37 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + run: | |
| 39 | + BASE_VERSION="0.0.1" # default version, can be modified as needed |
| 40 | + REF="${GITHUB_REF}" |
| 41 | + |
| 42 | + # Use tag version |
| 43 | + if [[ "$REF" == refs/tags/* ]]; then |
| 44 | + TAG_NAME="${REF#refs/tags/}" |
| 45 | + TAG_VERSION="${TAG_NAME#[vV]}" # 去掉 v/V 前缀 |
| 46 | + VERSION="$TAG_VERSION" |
| 47 | + echo "Detected tag: $TAG_NAME -> VERSION=$VERSION" |
| 48 | + fi |
| 49 | +
|
| 50 | + # set outputs for version |
| 51 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Log Version |
| 54 | + run: | |
| 55 | + echo "Current Version: ${{ steps.set_version.outputs.version }} " |
| 56 | +
|
| 57 | + - uses: actions/checkout@v3 |
| 58 | + - uses: actions/setup-dotnet@v4 |
| 59 | + with: |
| 60 | + dotnet-version: "8.0.x" |
| 61 | + - run: dotnet restore JobAgent.sln |
| 62 | + - run: dotnet build JobSamples/JobSamples.csproj -c Release -r ${{ matrix.runtime }} --self-contained false -o ./publish/JobSamples |
| 63 | + - run: dotnet publish JobAgent.Console/JobAgent.Console.csproj -c Release -r ${{ matrix.runtime }} --self-contained true -p:PublishSingleFile=true -o ./publish/JobAgent |
| 64 | + - name: Copy plugin to Console |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + mkdir -p ./publish/JobAgent/Plugins/JobSamples |
| 68 | + cp -r ./publish/JobSamples/* ./publish/JobAgent/Plugins/JobSamples/ |
| 69 | + rm -rf ./publish/JobSamples |
| 70 | + #- run: zip -r ./publish/JobAgent-${{ matrix.runtime }}.zip ./publish/JobAgent |
| 71 | + # note: Use PowerShell to create zip for better cross-platform support |
| 72 | + - name: Zip release |
| 73 | + shell: pwsh |
| 74 | + run: | |
| 75 | + if ($env:RUNNER_OS -eq "Windows") { |
| 76 | + $source = Resolve-Path ./publish/JobAgent |
| 77 | + $zip = "./publish/JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}.zip" |
| 78 | + Copy-Item -Path ./build/scripts/install.bat -Destination $source -Force |
| 79 | + Compress-Archive -Path "$source\*" -DestinationPath $zip -Force |
| 80 | + } else { |
| 81 | + & zip -r ./publish/JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}.zip ./publish/JobAgent |
| 82 | + } |
| 83 | +
|
| 84 | + - uses: actions/upload-artifact@v4 |
| 85 | + with: |
| 86 | + name: JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }} |
| 87 | + path: ./publish/JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}.zip |
| 88 | + |
| 89 | + release: |
| 90 | + name: Create Release |
| 91 | + needs: build |
| 92 | + runs-on: ubuntu-latest |
| 93 | + # 👇 only has a tag then run. |
| 94 | + if: startsWith(github.ref, 'refs/tags/') |
| 95 | + steps: |
| 96 | + - name: Log version |
| 97 | + shell: bash |
| 98 | + run: | |
| 99 | + echo "Version from build: ${{ needs.build.outputs.version }}" |
| 100 | + - uses: actions/checkout@v3 |
| 101 | + - name: Download artifacts |
| 102 | + uses: actions/download-artifact@v4 |
| 103 | + with: |
| 104 | + path: ./publish |
| 105 | + |
| 106 | + - name: Create Release & Upload assets |
| 107 | + id: create_release |
| 108 | + uses: softprops/action-gh-release@v2 |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + with: |
| 112 | + name: v${{ needs.build.outputs.version }} |
| 113 | + #tag_name: v${{ needs.build.outputs.version }} # It is necessary to have a TAG. When OrTag is triggered, this is not used, otherwise it will modify the original TAG. |
| 114 | + files: ./publish/**/*.zip |
| 115 | + draft: false |
| 116 | + #prerelease: ${{ needs.build.outputs.phase != 'Release' }} |
0 commit comments