Skip to content

Commit 1ac0f83

Browse files
authored
Merge pull request #134 from fluree/feature/release-on-tag
Publish Release on Tag
2 parents 347d5ec + a327d18 commit 1ac0f83

File tree

3 files changed

+152
-74
lines changed

3 files changed

+152
-74
lines changed

.github/workflows/ci.yml

+146-73
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,154 @@
11
name: CI
22
on:
3-
push:
4-
schedule:
5-
- cron: 13 21 * * *
3+
push:
4+
branches:
5+
- "**"
6+
tags:
7+
- "v*.*.*"
8+
schedule:
9+
- cron: 13 21 * * *
610

711
jobs:
8-
docker-build-cache:
9-
name: docker build cache
10-
runs-on: ci-cd
11-
steps:
12-
- uses: docker/setup-buildx-action@v3
13-
with:
14-
install: true
15-
- uses: docker/build-push-action@v5
16-
id: build
17-
with:
18-
cache-from: type=gha
19-
cache-to: type=gha,mode=max
20-
tags: fluree/server
21-
target: builder
22-
load: true
12+
docker-build-cache:
13+
name: docker build cache
14+
runs-on: ci-cd
15+
steps:
16+
- uses: docker/setup-buildx-action@v3
17+
with:
18+
install: true
19+
- uses: docker/build-push-action@v5
20+
id: build
21+
with:
22+
cache-from: type=gha
23+
cache-to: type=gha,mode=max
24+
tags: fluree/server
25+
target: builder
26+
load: true
2327

24-
cljfmt-check:
25-
name: cljfmt check
26-
runs-on: ubuntu-latest
27-
steps:
28-
- uses: actions/checkout@v4
29-
- uses: actions/setup-java@v4
30-
with:
31-
distribution: 'temurin'
32-
java-version: '21'
33-
- uses: DeLaGuardo/setup-clojure@12.5
34-
with:
35-
cli: 'latest'
36-
cljfmt: 'latest'
37-
- run: make cljfmt-check
28+
cljfmt-check:
29+
name: cljfmt check
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-java@v4
34+
with:
35+
distribution: "temurin"
36+
java-version: "21"
37+
- uses: DeLaGuardo/setup-clojure@12.5
38+
with:
39+
cli: "latest"
40+
cljfmt: "latest"
41+
- run: make cljfmt-check
3842

39-
clj-kondo-lint:
40-
name: clj-kondo lint
41-
runs-on: ubuntu-latest
42-
steps:
43-
- uses: actions/checkout@v4
44-
- uses: DeLaGuardo/setup-clojure@12.5
45-
with:
46-
cli: 'latest'
47-
clj-kondo: 'latest'
48-
- run: make clj-kondo-lint-ci
43+
clj-kondo-lint:
44+
name: clj-kondo lint
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: DeLaGuardo/setup-clojure@12.5
49+
with:
50+
cli: "latest"
51+
clj-kondo: "latest"
52+
- run: make clj-kondo-lint-ci
4953

50-
test:
51-
name: run tests
52-
needs: docker-build-cache
53-
runs-on: ci-cd
54-
steps:
55-
- uses: docker/setup-buildx-action@v3
56-
with:
57-
install: true
58-
- uses: docker/build-push-action@v5
59-
with:
60-
cache-from: type=gha
61-
cache-to: type=gha,mode=max
62-
tags: fluree/server
63-
target: builder
64-
load: true
65-
- name: Run tests
66-
run: docker run fluree/server make test
54+
test:
55+
name: run tests
56+
needs: docker-build-cache
57+
runs-on: ci-cd
58+
steps:
59+
- uses: docker/setup-buildx-action@v3
60+
with:
61+
install: true
62+
- uses: docker/build-push-action@v5
63+
with:
64+
cache-from: type=gha
65+
cache-to: type=gha,mode=max
66+
tags: fluree/server
67+
target: builder
68+
load: true
69+
- name: Run tests
70+
run: docker run fluree/server make test
6771

68-
notifications:
69-
name: send notifications
70-
if: always()
71-
runs-on: ubuntu-latest
72-
needs: [test]
73-
steps:
74-
- if: github.ref == 'refs/heads/main' && failure()
75-
env:
76-
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
77-
uses: voxmedia/github-action-slack-notify-build@v2
78-
with:
79-
channel: development
80-
status: FAILED
81-
color: danger
72+
release:
73+
name: create release
74+
if: startsWith(github.ref, 'refs/tags/v')
75+
needs: test
76+
runs-on: ubuntu-latest
77+
env:
78+
VERSION: ${{ github.ref_name }}
79+
IS_PRERELEASE: ${{ contains(github.ref_name, '-') }}
80+
steps:
81+
- uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 0 # ensure full history for branch detection
84+
85+
- name: Log release version
86+
run: |
87+
echo "VERSION=${{ env.VERSION }}"
88+
89+
- name: Set up Docker
90+
uses: docker/setup-buildx-action@v3
91+
92+
- name: Check if commit is on main
93+
run: |
94+
git fetch origin main --depth=1
95+
if git branch --contains $GITHUB_SHA | grep -q 'main'; then
96+
echo "IS_MAINLINE=true" >> $GITHUB_ENV
97+
else
98+
echo "IS_MAINLINE=false" >> $GITHUB_ENV
99+
fi
100+
101+
- name: Set tag variables
102+
id: tag_vars
103+
run: |
104+
echo "VERSION_TAG=fluree/server:${{ env.VERSION }}" >> $GITHUB_ENV
105+
if [[ "${IS_MAINLINE}" == "true" && "${{ env.IS_PRERELEASE }}" == "false" ]]; then
106+
echo "LATEST_TAG_IF_MAINLINE=fluree/server:latest" >> $GITHUB_ENV
107+
else
108+
echo "LATEST_TAG_IF_MAINLINE=" >> $GITHUB_ENV
109+
fi
110+
111+
- uses: docker/login-action@v3
112+
with:
113+
username: ${{ vars.DOCKER_HUB_USER }}
114+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
115+
116+
- name: Build and push Docker image
117+
uses: docker/build-push-action@v5
118+
with:
119+
context: .
120+
push: true
121+
tags: |
122+
${{ env.VERSION_TAG }}
123+
${{ env.LATEST_TAG_IF_MAINLINE }}
124+
platforms: linux/amd64,linux/arm64
125+
build-args: VERSION=${{ env.VERSION }}
126+
cache-from: type=gha
127+
cache-to: type=gha,mode=max
128+
129+
- name: Create GitHub release
130+
uses: softprops/action-gh-release@v1
131+
env:
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
with:
134+
tag_name: ${{ github.ref_name }}
135+
draft: false
136+
prerelease: ${{ env.IS_PRERELEASE }}
137+
generate_release_notes: true
138+
body: |
139+
Docker image: https://hub.docker.com/r/fluree/server/tags?name=${{ github.ref_name }}
140+
141+
notifications:
142+
name: send notifications
143+
if: always()
144+
runs-on: ubuntu-latest
145+
needs: [test, release]
146+
steps:
147+
- if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && failure()
148+
env:
149+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
150+
uses: voxmedia/github-action-slack-notify-build@v2
151+
with:
152+
channel: development
153+
status: FAILED
154+
color: danger

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM --platform=$BUILDPLATFORM clojure:temurin-17-tools-deps-1.11.1.1413-bullseye-slim AS builder
22

3+
ARG VERSION
4+
ENV VERSION=$VERSION
5+
36
RUN mkdir -p /usr/src/fluree-server
47
WORKDIR /usr/src/fluree-server
58

build.clj

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
[org.corfield.build :as bb]))
44

55
(def lib 'fluree/server)
6-
(def version (format "0.1.%s" (b/git-count-revs nil)))
6+
(def version
7+
(or (System/getenv "VERSION")
8+
(format "0.1.%s" (b/git-count-revs nil))))
79

810
(defn uber [_]
911
(bb/uber {:lib lib

0 commit comments

Comments
 (0)