|
| 1 | +# Attaches the web-only app to a GitHub Release as a zip, so a released version is a thing you can |
| 2 | +# download and serve rather than something you have to build. Tag a commit v1.2.3 and push the tag. |
| 3 | +# |
| 4 | +# The same tag also triggers publish-docker.yml, which pushes the backend edition to Docker Hub. The two |
| 5 | +# run independently -- nothing here waits on that -- but the notes written below name the image, because |
| 6 | +# a release that mentions only the zip reads as though the container does not exist. |
| 7 | +name: Release |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + tags: ['v*'] |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + tag: |
| 15 | + description: 'Existing tag to build and release (e.g. v1.2.3)' |
| 16 | + required: true |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +env: |
| 22 | + # Must match IMAGE_NAME in publish-docker.yml. Named in both because Actions has no way to share a |
| 23 | + # value between workflows short of a repository variable, which would then have to be configured |
| 24 | + # before either could run. Renaming the image means renaming it twice. |
| 25 | + IMAGE_NAME: graphdbviewer-server |
| 26 | + |
| 27 | +jobs: |
| 28 | + release: |
| 29 | + name: Package and publish the release |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v7 |
| 34 | + with: |
| 35 | + ref: ${{ inputs.tag || github.ref }} |
| 36 | + |
| 37 | + - uses: actions/setup-dotnet@v6 |
| 38 | + with: |
| 39 | + dotnet-version: '10.0.x' |
| 40 | + |
| 41 | + # The tag is the version, minus its leading v. Everything downstream is named from this. |
| 42 | + - name: Read the version from the tag |
| 43 | + run: | |
| 44 | + TAG="${{ inputs.tag || github.ref_name }}" |
| 45 | + echo "TAG=$TAG" >> "$GITHUB_ENV" |
| 46 | + echo "VERSION=${TAG#v}" >> "$GITHUB_ENV" |
| 47 | +
|
| 48 | + - name: Publish the web-only app |
| 49 | + run: dotnet publish GraphDBViewerWeb/GraphDBViewerWeb.csproj -c Release -p:WasmBuildNative=false -o publish |
| 50 | + |
| 51 | + # Zipped from inside wwwroot, so it unpacks as the site root rather than a nested folder — the |
| 52 | + # contents are what a static host serves. |
| 53 | + - name: Package |
| 54 | + run: | |
| 55 | + cd publish/wwwroot |
| 56 | + zip -qr "$GITHUB_WORKSPACE/graph-db-viewer-web-$VERSION.zip" . |
| 57 | +
|
| 58 | + - name: Create or update the release |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ github.token }} |
| 61 | + run: | |
| 62 | + if gh release view "$TAG" >/dev/null 2>&1; then |
| 63 | + gh release upload "$TAG" "graph-db-viewer-web-$VERSION.zip" --clobber |
| 64 | + else |
| 65 | + gh release create "$TAG" "graph-db-viewer-web-$VERSION.zip" \ |
| 66 | + --title "$TAG" \ |
| 67 | + --generate-notes |
| 68 | + fi |
| 69 | +
|
| 70 | + # Generated notes are commit subjects and nothing else, so the container is invisible to anyone |
| 71 | + # reading the release. Skipped when no Docker Hub account is configured, matching publish-docker.yml: |
| 72 | + # there is no image to point at then, and half an image name is worse than none. |
| 73 | + - name: Name the Docker image in the release notes |
| 74 | + if: vars.DOCKERHUB_USERNAME != '' |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ github.token }} |
| 77 | + IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} |
| 78 | + run: | |
| 79 | + BODY=$(gh release view "$TAG" --json body -q .body) |
| 80 | +
|
| 81 | + # Idempotent: re-running this workflow over an existing release must not stack the section up |
| 82 | + # twice, and must not overwrite notes somebody has edited by hand around it. |
| 83 | + if printf '%s' "$BODY" | grep -q '^## Docker image'; then |
| 84 | + echo "The notes already name the image." |
| 85 | + exit 0 |
| 86 | + fi |
| 87 | +
|
| 88 | + { |
| 89 | + printf '%s\n\n' "$BODY" |
| 90 | + printf '## Docker image\n\n' |
| 91 | + printf 'This version as a container — the backend edition, which adds a proxy for databases a\n' |
| 92 | + printf 'browser cannot reach (an endpoint with no CORS headers, plain http on an https page, Bolt,\n' |
| 93 | + printf 'or a host only the server can route to):\n\n' |
| 94 | + printf '```\n' |
| 95 | + printf 'docker run --rm -p 8080:8080 %s:%s\n' "$IMAGE" "$VERSION" |
| 96 | + printf '```\n\n' |
| 97 | + printf 'Then open http://localhost:8080. Published to Docker Hub from this same tag.\n\n' |
| 98 | + printf 'The zip attached to this release needs none of that: unpack it onto any static host and\n' |
| 99 | + printf 'open it. Everything runs in the browser, and the toggle for the server route hides itself\n' |
| 100 | + printf 'when there is no host answering behind it.\n' |
| 101 | + } > notes.md |
| 102 | +
|
| 103 | + gh release edit "$TAG" --notes-file notes.md |
0 commit comments