Skip to content

Commit 89255cc

Browse files
committed
ci: Automate releasing
With new make targets and GitHub Actions.
1 parent d800811 commit 89255cc

File tree

3 files changed

+87
-5
lines changed

3 files changed

+87
-5
lines changed

.github/workflows/publish.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Run checks
17+
run: make
18+
19+
- run: make dist
20+
21+
- name: Save build artifacts
22+
uses: actions/upload-artifact@v3
23+
with:
24+
name: artifacts
25+
path: dist/
26+
retention-days: 14
27+
if-no-files-found: error
28+
29+
release:
30+
needs: build
31+
32+
name: Release
33+
runs-on: ubuntu-latest
34+
timeout-minutes: 10
35+
permissions:
36+
contents: write
37+
38+
steps:
39+
- name: Extract build artifacts
40+
uses: actions/download-artifact@v3
41+
with:
42+
name: artifacts
43+
44+
- name: Prepare release
45+
uses: ncipollo/release-action@v1
46+
with:
47+
allowUpdates: true
48+
generateReleaseNotes: true
49+
artifacts: "*"

Makefile

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ TEST=./unittest
66

77
# MAIN TARGETS
88

9-
all:
9+
all: test check
10+
11+
clean:
12+
@echo '# Delete distributed files: rm -rf ./dist' >&2
13+
@rm -rf ./dist
1014

1115
info:
1216
@printf '# OS info: '
@@ -16,13 +20,39 @@ info:
1620
@echo; $(TEST) -v
1721

1822
check: $(LINT)
19-
@printf '# Static analysis: $(LINT) unittest tests/*.sh' >&2
23+
@printf '# Static analysis: $(LINT) unittest tests/*.sh\n' >&2
2024
@$(LINT) unittest tests/*.sh
2125

2226
test:
2327
@echo '# Unit tests: $(TEST)' >&2
2428
@$(TEST)
2529

30+
dist: unittest
31+
@echo '# Create release artifacts in ./dist' >&2
32+
@mkdir -p ./dist
33+
@cp unittest ./dist/unittest
34+
35+
@echo '# Create checksum' >&2
36+
@cd ./dist; sha256sum unittest >./unittest.sha256sum
37+
38+
release:
39+
@echo '# Update local branch' >&2
40+
@git pull --rebase
41+
@echo '# Create new release tag' >&2
42+
@PREV_VER_TAG=$$(git tag | grep "^v" | sed 's/^v//' | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1); \
43+
CURRENT_VER=$$(./unittest -v 2>&1 | cut -d' ' -f2); \
44+
if [ "$$PREV_VER_TAG" = "$$CURRENT_VER" ]; then \
45+
echo "ERROR: unittest is in the same version as previous release ($$PREV_VER_TAG). Aborting"; \
46+
exit 1; \
47+
fi; \
48+
printf 'Choose new version number (calver) for release [%s]: ' "$${CURRENT_VER:=23.11}"; \
49+
read -r VERSION; \
50+
if [ -z "$$VERSION" ]; then \
51+
VERSION="$$CURRENT_VER"; \
52+
fi; \
53+
git tag "v$$VERSION"; \
54+
git push --tags
55+
2656
# HELPERS
2757

2858
$(LINT):

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ chmod +x unittest
7676

7777
Use `make` (GNU or BSD):
7878

79-
- `make` - check dependencies
80-
- `make test` - runs test
81-
- `make check` - static code analysis
79+
- `make` - run checks
80+
- `make test` - run test
81+
- `make check` - perform static code analysis
82+
- `make dist` - prepare for distributing
83+
- `make clean` - remove distributed artifacts
84+
- `make release` - tag latest commit as a new release
8285
- `make info` - print system info (useful for debugging).
8386

8487
## Alternatives

0 commit comments

Comments
 (0)