| 1 | name: Release |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | inputs: |
| 6 | version: |
| 7 | description: "Release version (e.g. 1.2.3)" |
| 8 | required: true |
| 9 | type: string |
| 10 | prerelease: |
| 11 | description: "Mark as pre-release" |
| 12 | required: false |
| 13 | type: boolean |
| 14 | default: false |
| 15 | |
| 16 | env: |
| 17 | REGISTRY: ghcr.io |
| 18 | OWNER: ${{ github.repository_owner }} |
| 19 | |
| 20 | jobs: |
| 21 | release: |
| 22 | name: Build, Push & Release |
| 23 | runs-on: blacksmith-4vcpu-ubuntu-2404 |
| 24 | permissions: |
| 25 | contents: write |
| 26 | packages: write |
| 27 | |
| 28 | steps: |
| 29 | - name: Checkout |
| 30 | uses: actions/checkout@v4 |
| 31 | with: |
| 32 | fetch-depth: 0 |
| 33 | |
| 34 | - name: Setup Blacksmith Builder |
| 35 | uses: useblacksmith/setup-docker-builder@ab5c1da94f53f5cd75c1038092aa276dddfccbba # v1 |
| 36 | |
| 37 | - name: Log in to GHCR |
| 38 | uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 |
| 39 | with: |
| 40 | registry: ${{ env.REGISTRY }} |
| 41 | username: ${{ github.actor }} |
| 42 | password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | |
| 44 | - name: Resolve float tag |
| 45 | id: tags |
| 46 | run: echo "float=${{ inputs.prerelease == true && 'nightly' || 'latest' }}" >> "$GITHUB_OUTPUT" |
| 47 | |
| 48 | - name: Build and push dashboard |
| 49 | uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2 |
| 50 | with: |
| 51 | context: . |
| 52 | file: apps/web/Dockerfile |
| 53 | push: true |
| 54 | tags: | |
| 55 | ${{ env.REGISTRY }}/${{ env.OWNER }}/dashboard:${{ inputs.version }} |
| 56 | ${{ env.REGISTRY }}/${{ env.OWNER }}/dashboard:${{ steps.tags.outputs.float }} |
| 57 | build-args: | |
| 58 | APP_VERSION=${{ inputs.version }} |
| 59 | COMMIT_SHA=${{ github.sha }} |
| 60 | |
| 61 | - name: Build and push watchkeeper |
| 62 | uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2 |
| 63 | with: |
| 64 | context: . |
| 65 | file: apps/watchkeeper/Dockerfile |
| 66 | push: true |
| 67 | tags: | |
| 68 | ${{ env.REGISTRY }}/${{ env.OWNER }}/watchkeeper:${{ inputs.version }} |
| 69 | ${{ env.REGISTRY }}/${{ env.OWNER }}/watchkeeper:${{ steps.tags.outputs.float }} |
| 70 | |
| 71 | - name: Build and push migrate |
| 72 | uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2 |
| 73 | with: |
| 74 | context: . |
| 75 | file: packages/db/Dockerfile |
| 76 | push: true |
| 77 | tags: | |
| 78 | ${{ env.REGISTRY }}/${{ env.OWNER }}/migrate:${{ inputs.version }} |
| 79 | ${{ env.REGISTRY }}/${{ env.OWNER }}/migrate:${{ steps.tags.outputs.float }} |
| 80 | |
| 81 | - name: Generate changelog |
| 82 | id: changelog |
| 83 | env: |
| 84 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | run: | |
| 86 | if [ "${{ inputs.prerelease }}" = "true" ]; then |
| 87 | # For pre-releases, diff against the immediately preceding tag (stable or pre-release) |
| 88 | PREV_TAG=$(git describe --tags --abbrev=0 HEAD 2>/dev/null || echo "") |
| 89 | else |
| 90 | # For stable releases, diff against the last stable tag so that commits |
| 91 | # already summarised in pre-releases are included in the full release notes. |
| 92 | PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || echo "") |
| 93 | fi |
| 94 | |
| 95 | if [ -z "$PREV_TAG" ]; then |
| 96 | RANGE="HEAD" |
| 97 | else |
| 98 | RANGE="${PREV_TAG}..HEAD" |
| 99 | fi |
| 100 | |
| 101 | FEATURES=$(git log $RANGE --pretty=format:"- %s (%h)" --no-merges | grep -E "^- feat" || true) |
| 102 | FIXES=$(git log $RANGE --pretty=format:"- %s (%h)" --no-merges | grep -E "^- fix" || true) |
| 103 | OTHER=$(git log $RANGE --pretty=format:"- %s (%h)" --no-merges | grep -Ev "^- (feat|fix)" || true) |
| 104 | |
| 105 | # Resolve the actual GitHub username per commit via the API instead of |
| 106 | # guessing from the freeform display name, so credits tag the right account. |
| 107 | declare -A seen |
| 108 | CREDITS="" |
| 109 | while IFS=' ' read -r sha email name; do |
| 110 | [[ "$email" == *"[bot]"* || "$name" == *"[bot]"* || "$email" == *"github-actions"* ]] && continue |
| 111 | [[ -n "${seen[$email]:-}" ]] && continue |
| 112 | seen[$email]=1 |
| 113 | login=$(gh api "repos/${{ github.repository }}/commits/${sha}" --jq '.author.login // empty' 2>/dev/null || true) |
| 114 | CREDITS="${CREDITS}${login:-$name}"$'\n' |
| 115 | done < <(git log $RANGE --pretty=format:"%H %ae %aN" --no-merges) |
| 116 | CREDITS=$(printf '%s' "$CREDITS" | sed '/^$/d' | sort -u | sed 's|.*|[@&](https://github.com/&)|') |
| 117 | |
| 118 | { |
| 119 | echo "body<<EOF" |
| 120 | echo "## What's Changed" |
| 121 | echo "" |
| 122 | if [ -n "$FEATURES" ]; then |
| 123 | echo "### Features" |
| 124 | echo "$FEATURES" |
| 125 | echo "" |
| 126 | fi |
| 127 | if [ -n "$FIXES" ]; then |
| 128 | echo "### Bug Fixes" |
| 129 | echo "$FIXES" |
| 130 | echo "" |
| 131 | fi |
| 132 | if [ -n "$OTHER" ]; then |
| 133 | echo "### Other Changes" |
| 134 | echo "$OTHER" |
| 135 | echo "" |
| 136 | fi |
| 137 | if [ -n "$CREDITS" ]; then |
| 138 | echo "### Credits" |
| 139 | echo "$CREDITS" |
| 140 | echo "" |
| 141 | fi |
| 142 | echo "## Docker Images" |
| 143 | echo "" |
| 144 | echo '```sh' |
| 145 | echo "docker pull ghcr.io/${{ env.OWNER }}/dashboard:${{ inputs.version }}" |
| 146 | echo "docker pull ghcr.io/${{ env.OWNER }}/watchkeeper:${{ inputs.version }}" |
| 147 | echo "docker pull ghcr.io/${{ env.OWNER }}/migrate:${{ inputs.version }}" |
| 148 | echo '```' |
| 149 | echo "" |
| 150 | echo "## Deploy" |
| 151 | echo "" |
| 152 | if [ "${{ inputs.prerelease }}" = "true" ]; then |
| 153 | echo "### Install" |
| 154 | echo '```sh' |
| 155 | echo "bash <(curl -fsSL https://install.struxa.cloud) --nightly" |
| 156 | echo '```' |
| 157 | echo "" |
| 158 | echo "### Update" |
| 159 | echo '```sh' |
| 160 | echo "bash <(curl -fsSL https://install.struxa.cloud) update --nightly" |
| 161 | echo '```' |
| 162 | else |
| 163 | echo "### Install" |
| 164 | echo '```sh' |
| 165 | echo "bash <(curl -fsSL https://install.struxa.cloud)" |
| 166 | echo '```' |
| 167 | echo "" |
| 168 | echo "### Update" |
| 169 | echo '```sh' |
| 170 | echo "bash <(curl -fsSL https://install.struxa.cloud) update" |
| 171 | echo '```' |
| 172 | fi |
| 173 | echo "EOF" |
| 174 | } >> "$GITHUB_OUTPUT" |
| 175 | |
| 176 | - name: Create GitHub Release |
| 177 | uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 |
| 178 | with: |
| 179 | tag_name: v${{ inputs.version }} |
| 180 | name: v${{ inputs.version }} |
| 181 | body: ${{ steps.changelog.outputs.body }} |
| 182 | draft: true |
| 183 | prerelease: ${{ inputs.prerelease }} |
| 184 | files: docker-compose.prod.yml |
| 185 | token: ${{ secrets.GITHUB_TOKEN }} |