Build, Publish & Release (CKPool Solo) #69
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build, Publish & Release (CKPool Solo) | |
| on: | |
| workflow_dispatch: {} | |
| schedule: | |
| - cron: "31 5 * * *" # daily | |
| concurrency: | |
| group: cksolo | |
| cancel-in-progress: false | |
| env: | |
| DOCKERHUB_REPO: magicdude4eva/cksolo | |
| BUILD_CONTEXT: cksolo | |
| DOCKERFILE_PATH: cksolo/Dockerfile | |
| PLATFORM: linux/amd64 | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # to create a GitHub Release | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Detect latest solobtc commit | |
| id: latest | |
| run: | | |
| set -euo pipefail | |
| # Get latest commit on branch 'solobtc' | |
| fullsha=$(git ls-remote --heads https://bitbucket.org/ckolivas/ckpool-solo.git solobtc | awk '{print $1}') | |
| test -n "$fullsha" | |
| shortsha=${fullsha:0:12} | |
| echo "fullsha=$fullsha" >> "$GITHUB_OUTPUT" | |
| echo "shortsha=$shortsha" >> "$GITHUB_OUTPUT" | |
| echo "Latest solobtc: $fullsha ($shortsha)" | |
| - name: Skip if tag already on Docker Hub | |
| id: hubcheck | |
| run: | | |
| set -euo pipefail | |
| tag="solobtc-${{ steps.latest.outputs.shortsha }}" | |
| code=$(curl -s -o /dev/null -w "%{http_code}" \ | |
| "https://hub.docker.com/v2/repositories/${{ env.DOCKERHUB_REPO }}/tags/${tag}") | |
| echo "hub_status=$code" >> "$GITHUB_OUTPUT" | |
| if [ "$code" = "200" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "Tag $tag already exists - skipping." | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Tag $tag not found - will build." | |
| fi | |
| - name: Set up Buildx | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.BUILD_CONTEXT }} | |
| file: ${{ env.DOCKERFILE_PATH }} | |
| platforms: ${{ env.PLATFORM }} | |
| push: true | |
| build-args: | | |
| CKPOOL_REF=${{ steps.latest.outputs.fullsha }} | |
| tags: | | |
| ${{ env.DOCKERHUB_REPO }}:latest | |
| ${{ env.DOCKERHUB_REPO }}:solobtc-${{ steps.latest.outputs.shortsha }} | |
| labels: | | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=solobtc-${{ steps.latest.outputs.shortsha }} | |
| org.opencontainers.image.title=cksolo | |
| org.opencontainers.image.description=CKPool Solo - Lightweight stratum server for Bitcoin solo mining | |
| - name: Update Docker Hub description from ./cksolo/README.md | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| uses: peter-evans/dockerhub-description@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| repository: ${{ env.DOCKERHUB_REPO }} | |
| readme-filepath: ./cksolo/README.md | |
| short-description: CKPool Solo - Lightweight stratum server for Bitcoin solo mining | |
| - name: Prepare release artifacts | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| run: | | |
| set -euo pipefail | |
| echo "${{ steps.latest.outputs.fullsha }}" > upstream-fullsha.txt | |
| echo "solobtc-${{ steps.latest.outputs.shortsha }}" > image-tag.txt | |
| echo "${{ steps.build.outputs.digest }}" > image-digest.txt | |
| - name: Build commit changelog since last release | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| id: changelog | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| new_full='${{ steps.latest.outputs.fullsha }}' | |
| mkdir -p _artifacts | |
| # Find previous cksolo release in this repo (if any) and get its upstream SHA | |
| prev_tag=$(gh release list --limit 200 --json tagName,isDraft,isPrerelease,publishedAt \ | |
| --jq '[.[] | select(.tagName | startswith("cksolo-")) | select(.isDraft==false and .isPrerelease==false)] | |
| | sort_by(.publishedAt) | last // empty | .tagName') | |
| if [ -n "${prev_tag:-}" ]; then | |
| echo "Prev release: $prev_tag" | |
| gh release download "$prev_tag" -p upstream-fullsha.txt -O _artifacts/prev-upstream-fullsha.txt | |
| prev_full=$(cat _artifacts/prev-upstream-fullsha.txt | tr -d '\r\n') | |
| else | |
| echo "No previous cksolo release found." | |
| prev_full="" | |
| fi | |
| # Build commit list | |
| echo "# Changes in ckpool-solo (solobtc)" > _artifacts/release-body.md | |
| echo "" >> _artifacts/release-body.md | |
| echo "**Upstream commit:** \`${new_full}\`" >> _artifacts/release-body.md | |
| echo "" >> _artifacts/release-body.md | |
| if [ -n "$prev_full" ]; then | |
| echo "Comparing range: $prev_full..$new_full" | |
| git clone --filter=blob:none https://bitbucket.org/ckolivas/ckpool-solo.git upstream | |
| cd upstream | |
| git checkout solobtc | |
| # Ensure both commits exist locally | |
| git fetch origin "$prev_full" "$new_full" --depth=1 || git fetch origin solobtc --unshallow || true | |
| echo "" >> ../_artifacts/release-body.md | |
| echo "## Commits since last release" >> ../_artifacts/release-body.md | |
| echo "" >> ../_artifacts/release-body.md | |
| # Format: shortsha subject (author) | |
| if git merge-base --is-ancestor "$prev_full" "$new_full"; then | |
| git log --no-merges --pretty=format:'- %h %s (%an)' "$prev_full..$new_full" >> ../_artifacts/release-body.md | |
| else | |
| echo "_Note: previous SHA is not an ancestor of the new SHA; showing short log of solobtc branch._" >> ../_artifacts/release-body.md | |
| git log --no-merges --pretty=format:'- %h %s (%an)' -n 50 >> ../_artifacts/release-body.md | |
| fi | |
| cd .. | |
| else | |
| echo "_First release detected. Commit list not available._" >> _artifacts/release-body.md | |
| fi | |
| echo "" >> _artifacts/release-body.md | |
| echo "## Docker Hub" >> _artifacts/release-body.md | |
| echo "- https://hub.docker.com/r/${{ env.DOCKERHUB_REPO }}/tags?name=solobtc-${{ steps.latest.outputs.shortsha }}" >> _artifacts/release-body.md | |
| echo "- https://hub.docker.com/r/${{ env.DOCKERHUB_REPO }}/tags?name=latest" >> _artifacts/release-body.md | |
| echo "" >> _artifacts/release-body.md | |
| echo "## Image digest" >> _artifacts/release-body.md | |
| echo '```' >> _artifacts/release-body.md | |
| echo "${{ steps.build.outputs.digest }}" >> _artifacts/release-body.md | |
| echo '```' >> _artifacts/release-body.md | |
| - name: Create GitHub Release in btc-fullnode-stack | |
| if: steps.hubcheck.outputs.skip == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: cksolo-${{ steps.latest.outputs.shortsha }} | |
| name: CKPool Solo (solobtc @ ${{ steps.latest.outputs.shortsha }}) | |
| target_commitish: ${{ github.sha }} | |
| generate_release_notes: false | |
| body_path: _artifacts/release-body.md | |
| files: | | |
| upstream-fullsha.txt | |
| image-tag.txt | |
| image-digest.txt | |
| - name: Summary | |
| run: | | |
| echo "Upstream full SHA: ${{ steps.latest.outputs.fullsha }}" | |
| echo "Short SHA: ${{ steps.latest.outputs.shortsha }}" | |
| echo "Hub status: ${{ steps.hubcheck.outputs.hub_status }}" | |
| echo "Skipped: ${{ steps.hubcheck.outputs.skip }}" |