|
| 1 | +name: Build Release Packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + packages: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + publish: |
| 15 | + name: Publish ${{ matrix.base_name }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - rid: win-x64 |
| 22 | + base_name: RouterOSMCPSharp-win-x64 |
| 23 | + artifact_name: RouterOSMCPSharp-win-x64 |
| 24 | + self_contained: false |
| 25 | + - rid: linux-x64 |
| 26 | + base_name: RouterOSMCPSharp-linux-x64 |
| 27 | + artifact_name: RouterOSMCPSharp-linux-x64 |
| 28 | + self_contained: false |
| 29 | + - rid: linux-arm64 |
| 30 | + base_name: RouterOSMCPSharp-linux-arm64 |
| 31 | + artifact_name: RouterOSMCPSharp-linux-arm64 |
| 32 | + self_contained: false |
| 33 | + - rid: win-x64 |
| 34 | + base_name: RouterOSMCPSharp-win-x64-standalone |
| 35 | + artifact_name: RouterOSMCPSharp-win-x64-standalone |
| 36 | + self_contained: true |
| 37 | + - rid: linux-x64 |
| 38 | + base_name: RouterOSMCPSharp-linux-x64-standalone |
| 39 | + artifact_name: RouterOSMCPSharp-linux-x64-standalone |
| 40 | + self_contained: true |
| 41 | + - rid: linux-arm64 |
| 42 | + base_name: RouterOSMCPSharp-linux-arm64-standalone |
| 43 | + artifact_name: RouterOSMCPSharp-linux-arm64-standalone |
| 44 | + self_contained: true |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Check out code |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Compute package version |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 54 | + echo "PACKAGE_VERSION=${GITHUB_REF_NAME}" >> "$GITHUB_ENV" |
| 55 | + else |
| 56 | + echo "PACKAGE_VERSION=dev-${GITHUB_RUN_NUMBER}" >> "$GITHUB_ENV" |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Set up .NET |
| 60 | + uses: actions/setup-dotnet@v4 |
| 61 | + with: |
| 62 | + dotnet-version: 8.0.x |
| 63 | + |
| 64 | + - name: Restore |
| 65 | + run: dotnet restore RouterOSMCPSharp.sln |
| 66 | + |
| 67 | + - name: Build |
| 68 | + run: dotnet build RouterOSMCPSharp.sln -c Release --no-restore |
| 69 | + |
| 70 | + - name: Test |
| 71 | + run: dotnet test RouterOSMCPSharp.sln -c Release --no-build --verbosity normal |
| 72 | + |
| 73 | + - name: Publish ${{ matrix.rid }} |
| 74 | + run: > |
| 75 | + dotnet publish RouterOSMCPSharp.csproj |
| 76 | + -c Release |
| 77 | + -r ${{ matrix.rid }} |
| 78 | + --self-contained ${{ matrix.self_contained }} |
| 79 | + -o publish/${{ matrix.rid }}-${{ matrix.self_contained }} |
| 80 | +
|
| 81 | + - name: Package ${{ matrix.rid }} |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + cd publish/${{ matrix.rid }}-${{ matrix.self_contained }} |
| 85 | + zip -r "../../${{ matrix.base_name }}-${PACKAGE_VERSION}.zip" . |
| 86 | +
|
| 87 | + - name: Upload workflow artifact |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: ${{ matrix.artifact_name }} |
| 91 | + path: ${{ matrix.base_name }}-${{ env.PACKAGE_VERSION }}.zip |
| 92 | + if-no-files-found: error |
| 93 | + |
| 94 | + docker: |
| 95 | + name: Build multi-arch Docker image |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: publish |
| 98 | + |
| 99 | + steps: |
| 100 | + - name: Check out code |
| 101 | + uses: actions/checkout@v4 |
| 102 | + |
| 103 | + - name: Compute package version |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 107 | + VERSION="${GITHUB_REF_NAME#v}" |
| 108 | + else |
| 109 | + VERSION="dev-${GITHUB_RUN_NUMBER}" |
| 110 | + fi |
| 111 | + echo "PACKAGE_VERSION=${VERSION}" >> "$GITHUB_ENV" |
| 112 | + echo "IMAGE_REPO=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" |
| 113 | +
|
| 114 | + - name: Set up QEMU |
| 115 | + uses: docker/setup-qemu-action@v3 |
| 116 | + |
| 117 | + - name: Set up Docker Buildx |
| 118 | + uses: docker/setup-buildx-action@v3 |
| 119 | + |
| 120 | + - name: Log in to GitHub Container Registry |
| 121 | + uses: docker/login-action@v3 |
| 122 | + with: |
| 123 | + registry: ghcr.io |
| 124 | + username: ${{ github.actor }} |
| 125 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 126 | + |
| 127 | + - name: Compute docker tags |
| 128 | + id: tags |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + TAGS="${IMAGE_REPO}:${PACKAGE_VERSION}" |
| 132 | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 133 | + TAGS="${TAGS},${IMAGE_REPO}:latest" |
| 134 | + fi |
| 135 | + echo "tags=${TAGS}" >> "$GITHUB_OUTPUT" |
| 136 | +
|
| 137 | + - name: Build and push multi-arch image |
| 138 | + uses: docker/build-push-action@v6 |
| 139 | + with: |
| 140 | + context: . |
| 141 | + file: Dockerfile |
| 142 | + platforms: linux/amd64,linux/arm64 |
| 143 | + push: true |
| 144 | + tags: ${{ steps.tags.outputs.tags }} |
| 145 | + provenance: false |
| 146 | + cache-from: type=gha |
| 147 | + cache-to: type=gha,mode=max |
| 148 | + |
| 149 | + release: |
| 150 | + name: Publish GitHub release |
| 151 | + if: startsWith(github.ref, 'refs/tags/') |
| 152 | + needs: [publish, docker] |
| 153 | + runs-on: ubuntu-latest |
| 154 | + |
| 155 | + steps: |
| 156 | + - name: Check out code |
| 157 | + uses: actions/checkout@v4 |
| 158 | + |
| 159 | + - name: Compute package version |
| 160 | + shell: bash |
| 161 | + run: echo "PACKAGE_VERSION=${GITHUB_REF_NAME}" >> "$GITHUB_ENV" |
| 162 | + |
| 163 | + - name: Download packaged artifacts |
| 164 | + uses: actions/download-artifact@v4 |
| 165 | + with: |
| 166 | + path: release-assets |
| 167 | + |
| 168 | + - name: Show release assets |
| 169 | + shell: bash |
| 170 | + run: find release-assets -maxdepth 2 -type f | sort |
| 171 | + |
| 172 | + - name: Create release if missing |
| 173 | + env: |
| 174 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 175 | + run: | |
| 176 | + gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1 || \ |
| 177 | + gh release create "${GITHUB_REF_NAME}" --generate-notes |
| 178 | +
|
| 179 | + - name: Upload release assets |
| 180 | + env: |
| 181 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 182 | + shell: bash |
| 183 | + run: | |
| 184 | + gh release upload "${GITHUB_REF_NAME}" \ |
| 185 | + release-assets/RouterOSMCPSharp-win-x64/RouterOSMCPSharp-win-x64-${PACKAGE_VERSION}.zip \ |
| 186 | + release-assets/RouterOSMCPSharp-linux-x64/RouterOSMCPSharp-linux-x64-${PACKAGE_VERSION}.zip \ |
| 187 | + release-assets/RouterOSMCPSharp-linux-arm64/RouterOSMCPSharp-linux-arm64-${PACKAGE_VERSION}.zip \ |
| 188 | + release-assets/RouterOSMCPSharp-win-x64-standalone/RouterOSMCPSharp-win-x64-standalone-${PACKAGE_VERSION}.zip \ |
| 189 | + release-assets/RouterOSMCPSharp-linux-x64-standalone/RouterOSMCPSharp-linux-x64-standalone-${PACKAGE_VERSION}.zip \ |
| 190 | + release-assets/RouterOSMCPSharp-linux-arm64-standalone/RouterOSMCPSharp-linux-arm64-standalone-${PACKAGE_VERSION}.zip \ |
| 191 | + --clobber |
0 commit comments