|
| 1 | +--- |
| 2 | +name: CD |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + artifact-action: |
| 7 | + description: Artifact action |
| 8 | + type: choice |
| 9 | + required: true |
| 10 | + default: none |
| 11 | + options: |
| 12 | + - none |
| 13 | + - build |
| 14 | + - build-release |
| 15 | + image-action: |
| 16 | + description: Container image action |
| 17 | + type: choice |
| 18 | + required: true |
| 19 | + default: none |
| 20 | + options: |
| 21 | + - none |
| 22 | + - build |
| 23 | + - build-release |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: read |
| 31 | + |
| 32 | +jobs: |
| 33 | + artifact: |
| 34 | + if: github.repository_owner == 'jspaste' && inputs.artifact-action != 'none' |
| 35 | + name: Release artifact |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + attestations: write |
| 39 | + contents: write |
| 40 | + id-token: write |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Harden Runner |
| 44 | + uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 |
| 45 | + with: |
| 46 | + egress-policy: audit |
| 47 | + |
| 48 | + - name: Setup Bun |
| 49 | + uses: oven-sh/setup-bun@4bc047ad259df6fc24a6c9b0f9a0cb08cf17fbe5 # v2.0.1 |
| 50 | + |
| 51 | + - name: Save context |
| 52 | + id: ctx |
| 53 | + env: |
| 54 | + CTX_BRANCH: ${{ github.head_ref || github.ref_name }} |
| 55 | + CTX_SHA: ${{ github.event.pull_request.head.sha || github.sha }} |
| 56 | + run: | |
| 57 | + echo "branch=${CTX_BRANCH}" >>"$GITHUB_OUTPUT" |
| 58 | + echo "sha=${CTX_SHA}" >>"$GITHUB_OUTPUT" |
| 59 | + echo "sha_short=${CTX_SHA::7}" >>"$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Save tags |
| 62 | + id: tags |
| 63 | + env: |
| 64 | + BRANCH: ${{ steps.ctx.outputs.branch }} |
| 65 | + SHA_SHORT: ${{ steps.ctx.outputs.sha_short }} |
| 66 | + run: | |
| 67 | + TIMESTAMP="$(date +%Y.%m.%d)" |
| 68 | +
|
| 69 | + if [[ "${BRANCH}" == "stable" ]]; then |
| 70 | + TAG="latest" |
| 71 | + else |
| 72 | + TAG="snapshot" |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "tag=${TAG}" >>"$GITHUB_OUTPUT" |
| 76 | + echo "extended=${TIMESTAMP}-${SHA_SHORT}" >>"$GITHUB_OUTPUT" |
| 77 | +
|
| 78 | + - name: Checkout |
| 79 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 80 | + with: |
| 81 | + persist-credentials: false |
| 82 | + |
| 83 | + - name: Install deps |
| 84 | + run: bun install --frozen-lockfile |
| 85 | + |
| 86 | + - name: Build artifact |
| 87 | + run: | |
| 88 | + bun run build:server |
| 89 | +
|
| 90 | + bun run build:standalone:darwin-arm64 |
| 91 | + chmod 755 ./dist/server |
| 92 | + tar -c --owner=0 --group=0 --mtime='now' --utc .env.example LICENSE README.md -C ./dist/ server | xz -z -6 >./dist/backend_${{ steps.tags.outputs.tag }}_darwin-arm64.tar.xz |
| 93 | + tar -tJf ./dist/backend_${{ steps.tags.outputs.tag }}_darwin-arm64.tar.xz >/dev/null |
| 94 | +
|
| 95 | + bun run build:standalone:linux-amd64-glibc |
| 96 | + chmod 755 ./dist/server |
| 97 | + tar -c --owner=0 --group=0 --mtime='now' --utc .env.example LICENSE README.md -C ./dist/ server | xz -z -6 >./dist/backend_${{ steps.tags.outputs.tag }}_linux-amd64-glibc.tar.xz |
| 98 | + tar -tJf ./dist/backend_${{ steps.tags.outputs.tag }}_linux-amd64-glibc.tar.xz >/dev/null |
| 99 | +
|
| 100 | + bun run build:standalone:linux-amd64-musl |
| 101 | + chmod 755 ./dist/server |
| 102 | + tar -c --owner=0 --group=0 --mtime='now' --utc .env.example LICENSE README.md -C ./dist/ server | xz -z -6 >./dist/backend_${{ steps.tags.outputs.tag }}_linux-amd64-musl.tar.xz |
| 103 | + tar -tJf ./dist/backend_${{ steps.tags.outputs.tag }}_linux-amd64-musl.tar.xz >/dev/null |
| 104 | +
|
| 105 | + bun run build:standalone:linux-arm64-glibc |
| 106 | + chmod 755 ./dist/server |
| 107 | + tar -c --owner=0 --group=0 --mtime='now' --utc .env.example LICENSE README.md -C ./dist/ server | xz -z -6 >./dist/backend_${{ steps.tags.outputs.tag }}_linux-arm64-glibc.tar.xz |
| 108 | + tar -tJf ./dist/backend_${{ steps.tags.outputs.tag }}_linux-arm64-glibc.tar.xz >/dev/null |
| 109 | +
|
| 110 | + bun run build:standalone:linux-arm64-musl |
| 111 | + chmod 755 ./dist/server |
| 112 | + tar -c --owner=0 --group=0 --mtime='now' --utc .env.example LICENSE README.md -C ./dist/ server | xz -z -6 >./dist/backend_${{ steps.tags.outputs.tag }}_linux-arm64-musl.tar.xz |
| 113 | + tar -tJf ./dist/backend_${{ steps.tags.outputs.tag }}_linux-arm64-musl.tar.xz >/dev/null |
| 114 | +
|
| 115 | + bun run build:standalone:windows-amd64 |
| 116 | + chmod 755 ./dist/server.exe |
| 117 | + zip -j -X -9 -l -o ./dist/backend_${{ steps.tags.outputs.tag }}_windows-amd64.zip .env.example LICENSE README.md ./dist/server.exe |
| 118 | + zip -T ./dist/backend_${{ steps.tags.outputs.tag }}_windows-amd64.zip |
| 119 | +
|
| 120 | + - if: inputs.artifact-action == 'build-release' |
| 121 | + name: Release artifact |
| 122 | + uses: ncipollo/release-action@440c8c1cb0ed28b9f43e4d1d670870f059653174 # v1.16.0 |
| 123 | + with: |
| 124 | + name: ${{ steps.tags.outputs.extended }} |
| 125 | + tag: ${{ steps.tags.outputs.extended }} |
| 126 | + artifacts: dist/*.tar.xz,dist/*.zip |
| 127 | + makeLatest: true |
| 128 | + prerelease: ${{ steps.ctx.outputs.branch != 'stable' }} |
| 129 | + generateReleaseNotes: ${{ steps.ctx.outputs.branch == 'stable' }} |
| 130 | + |
| 131 | + - if: inputs.artifact-action == 'build-release' |
| 132 | + name: Attest artifact |
| 133 | + uses: actions/attest-build-provenance@c074443f1aee8d4aeeae555aebba3282517141b2 # v2.2.3 |
| 134 | + with: |
| 135 | + subject-path: | |
| 136 | + dist/*.tar.xz |
| 137 | + dist/*.zip |
| 138 | +
|
| 139 | + container: |
| 140 | + if: github.repository_owner == 'jspaste' && inputs.image-action != 'none' |
| 141 | + name: Release container image |
| 142 | + runs-on: ubuntu-latest |
| 143 | + env: |
| 144 | + REGISTRY: ghcr.io |
| 145 | + |
| 146 | + permissions: |
| 147 | + attestations: write |
| 148 | + id-token: write |
| 149 | + packages: write |
| 150 | + |
| 151 | + steps: |
| 152 | + - name: Harden Runner |
| 153 | + uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 |
| 154 | + with: |
| 155 | + egress-policy: audit |
| 156 | + |
| 157 | + - name: Save context |
| 158 | + id: ctx |
| 159 | + env: |
| 160 | + CTX_BRANCH: ${{ github.head_ref || github.ref_name }} |
| 161 | + CTX_SHA: ${{ github.event.pull_request.head.sha || github.sha }} |
| 162 | + run: | |
| 163 | + echo "branch=${CTX_BRANCH}" >>"$GITHUB_OUTPUT" |
| 164 | + echo "sha=${CTX_SHA}" >>"$GITHUB_OUTPUT" |
| 165 | + echo "sha_short=${CTX_SHA::7}" >>"$GITHUB_OUTPUT" |
| 166 | +
|
| 167 | + - name: Save tags |
| 168 | + id: tags |
| 169 | + env: |
| 170 | + BRANCH: ${{ steps.ctx.outputs.branch }} |
| 171 | + SHA: ${{ steps.ctx.outputs.sha }} |
| 172 | + SHA_SHORT: ${{ steps.ctx.outputs.sha_short }} |
| 173 | + run: | |
| 174 | + TIMESTAMP="$(date +%Y.%m.%d)" |
| 175 | + TIMESTAMP_ISO="$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 176 | +
|
| 177 | + if [[ "${BRANCH}" == "stable" ]]; then |
| 178 | + TAGS+=("latest") |
| 179 | + else |
| 180 | + TAGS+=("snapshot") |
| 181 | + fi |
| 182 | +
|
| 183 | + TAGS+=("${SHA}") |
| 184 | + TAGS+=("${TIMESTAMP}-${SHA_SHORT}") |
| 185 | +
|
| 186 | + echo "timestamp=${TIMESTAMP}" >>"$GITHUB_OUTPUT" |
| 187 | + echo "timestamp_iso=${TIMESTAMP_ISO}" >>"$GITHUB_OUTPUT" |
| 188 | + echo "version=${TIMESTAMP}-${SHA_SHORT}" >>"$GITHUB_OUTPUT" |
| 189 | + echo "list=${TAGS[*]}" >>"$GITHUB_OUTPUT" |
| 190 | +
|
| 191 | + - name: Checkout |
| 192 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 193 | + with: |
| 194 | + persist-credentials: false |
| 195 | + |
| 196 | + - name: Build image |
| 197 | + id: build-image |
| 198 | + uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13 |
| 199 | + with: |
| 200 | + containerfiles: Dockerfile |
| 201 | + platforms: linux/amd64,linux/arm64 |
| 202 | + image: ${{ github.repository }} |
| 203 | + layers: true |
| 204 | + oci: true |
| 205 | + tags: ${{ steps.tags.outputs.list }} |
| 206 | + extra-args: | |
| 207 | + --squash |
| 208 | + --identity-label=false |
| 209 | + --label=org.opencontainers.image.created=${{ steps.tags.outputs.timestamp_iso }} |
| 210 | + --label=org.opencontainers.image.revision=${{ steps.ctx.outputs.sha }} |
| 211 | + --label=org.opencontainers.image.version=${{ steps.tags.outputs.version }} |
| 212 | +
|
| 213 | + - if: inputs.image-action == 'build-release' |
| 214 | + name: Login to GHCR |
| 215 | + uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7 |
| 216 | + with: |
| 217 | + username: ${{ github.repository_owner }} |
| 218 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 219 | + registry: ${{ env.REGISTRY }} |
| 220 | + |
| 221 | + - if: inputs.image-action == 'build-release' |
| 222 | + name: Push to GHCR |
| 223 | + id: push-image |
| 224 | + uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8 |
| 225 | + with: |
| 226 | + image: ${{ steps.build-image.outputs.image }} |
| 227 | + tags: ${{ steps.build-image.outputs.tags }} |
| 228 | + registry: ${{ env.REGISTRY }} |
| 229 | + |
| 230 | + - if: inputs.image-action == 'build-release' |
| 231 | + name: Attest image |
| 232 | + uses: actions/attest-build-provenance@c074443f1aee8d4aeeae555aebba3282517141b2 # v2.2.3 |
| 233 | + with: |
| 234 | + subject-name: "${{ env.REGISTRY }}/${{ steps.build-image.outputs.image }}" |
| 235 | + subject-digest: ${{ steps.push-image.outputs.digest }} |
| 236 | + push-to-registry: false |
0 commit comments