|
| 1 | +name: Release & Deploy to Clojars |
| 2 | + |
| 3 | +# Publishes com.blockether/bridge to Clojars on a v* tag. Mirrors |
| 4 | +# Blockether/svar. Required org secret: CLOJARS_DEPLOY_TOKEN (deploy token for |
| 5 | +# the blockether-deployer account, scoped to the com.blockether group). |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: ['v*'] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + name: Release & Deploy to Clojars |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v5 |
| 19 | + with: |
| 20 | + ref: main |
| 21 | + fetch-depth: 1 |
| 22 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + |
| 24 | + - name: Fetch tags and changelog history |
| 25 | + run: | |
| 26 | + git fetch --tags --no-recurse-submodules origin |
| 27 | + git fetch --deepen=200 origin main |
| 28 | +
|
| 29 | + - uses: actions/setup-java@v5 |
| 30 | + with: |
| 31 | + distribution: temurin |
| 32 | + java-version: '21' |
| 33 | + |
| 34 | + - uses: DeLaGuardo/setup-clojure@13.6.1 |
| 35 | + with: |
| 36 | + cli: latest |
| 37 | + |
| 38 | + - uses: actions/cache@v5 |
| 39 | + with: |
| 40 | + path: | |
| 41 | + ~/.m2/repository |
| 42 | + ~/.gitlibs |
| 43 | + ~/.clojure/.cpcache |
| 44 | + key: deps-${{ runner.os }}-${{ hashFiles('deps.edn') }} |
| 45 | + restore-keys: | |
| 46 | + deps-${{ runner.os }}- |
| 47 | +
|
| 48 | + - name: Generate changelog |
| 49 | + run: | |
| 50 | + PREV_TAG=$(git tag --sort=-v:refname | head -n 2 | tail -n 1) |
| 51 | + CURRENT_TAG=${{ github.ref_name }} |
| 52 | + if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" = "$CURRENT_TAG" ]; then |
| 53 | + CHANGELOG=$(git log --pretty=format:"- %s (%h)" $CURRENT_TAG) |
| 54 | + else |
| 55 | + CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${PREV_TAG}..${CURRENT_TAG}) |
| 56 | + fi |
| 57 | + { |
| 58 | + echo "## What's Changed" |
| 59 | + echo "" |
| 60 | + echo "$CHANGELOG" |
| 61 | + echo "" |
| 62 | + echo "**Full Changelog**: https://github.com/Blockether/bridge/compare/${PREV_TAG}...${CURRENT_TAG}" |
| 63 | + } > /tmp/release_body.md |
| 64 | +
|
| 65 | + - name: Create GitHub Release |
| 66 | + uses: softprops/action-gh-release@v3 |
| 67 | + with: |
| 68 | + body_path: /tmp/release_body.md |
| 69 | + |
| 70 | + - name: Check if version exists on Clojars |
| 71 | + id: check-clojars |
| 72 | + run: | |
| 73 | + VERSION="${GITHUB_REF_NAME#v}" |
| 74 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ |
| 75 | + "https://repo.clojars.org/com/blockether/bridge/$VERSION/bridge-$VERSION.jar") |
| 76 | + if [ "$STATUS" = "200" ]; then |
| 77 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 78 | + echo "::notice::Version $VERSION already exists on Clojars — skipping deploy" |
| 79 | + else |
| 80 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Build & Deploy to Clojars |
| 84 | + if: steps.check-clojars.outputs.exists != 'true' |
| 85 | + env: |
| 86 | + VERSION: ${{ github.ref_name }} |
| 87 | + CLOJARS_USERNAME: blockether-deployer |
| 88 | + CLOJARS_PASSWORD: ${{ secrets.CLOJARS_DEPLOY_TOKEN }} |
| 89 | + run: clojure -T:build deploy |
0 commit comments