Skip to content

Commit 7e57f20

Browse files
committed
Automatic release scripts and workflow (#386)
1 parent 783c338 commit 7e57f20

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

.github/workflows/publish.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: opam-repository
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
env:
12+
# allow opam depext to yes package manager prompts
13+
OPAMCONFIRMLEVEL: unsafe-yes
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v5
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true
20+
21+
- name: Setup OCaml
22+
uses: ocaml/setup-ocaml@v3
23+
with:
24+
ocaml-compiler: "5.3"
25+
26+
- name: Install dependencies
27+
run: |
28+
opam pin https://github.com/ocaml/opam.git
29+
opam pin https://github.com/filipeom/opam-publish.git#834e67659bfb608f51c8299263324efd1e33a263
30+
opam install opam-publish
31+
32+
- name: Publish
33+
env:
34+
OPAM_PUBLISH_GH_TOKEN: ${{ secrets.OPAM_PUBLISH_GH_TOKEN }}
35+
run: ./scripts/publish.sh

scripts/create-release.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TAG="$1"
5+
BRANCH="release/v$TAG"
6+
7+
if ! command -v git-cliff >/dev/null; then
8+
echo "git-cliff is not installed. Run: cargo install git-cliff"
9+
exit 1
10+
fi
11+
12+
# Fail fast if opam-publish isn't installed
13+
if ! command -v gh >/dev/null; then
14+
echo "github-clie is not installed."
15+
exit 1
16+
fi
17+
18+
git switch -c $BRANCH
19+
git-cliff -c cliff.toml -t $TAG -o CHANGES.md
20+
git add CHANGES.md
21+
git commit -m "Release $TAG"
22+
git push -u origin $BRANCH
23+
24+
gh pr create \
25+
--base "main" \
26+
--head "$BRANCH" \
27+
--title "Release $TAG" \
28+
--body "Automated Release $TAG"

scripts/publish.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TAG="$(git describe --tags --exact-match 2>/dev/null || true)"
5+
6+
if [ -z "$TAG" ]; then
7+
echo "No tag on the current commit. Nothing to release."
8+
exit 0
9+
fi
10+
11+
echo "Found tag $TAG on HEAD. Releasing…"
12+
13+
# Verify that the GitHub token exists
14+
if [[ -z "${OPAM_PUBLISH_GH_TOKEN:-}" ]]; then
15+
echo "Error: OPAM_PUBLISH_GH_TOKEN is not set."
16+
exit 1
17+
fi
18+
19+
# Create PR change log
20+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^)
21+
git shortlog $PREV_TAG..$TAG > shortlog.txt
22+
23+
# Remove pin depends which are not allowed in opam-repository
24+
sed -i '/^pin-depends:/,$d' smtml.opam
25+
26+
opam exec -- opam-publish \
27+
--tag="$TAG" \
28+
--msg-file=./shortlog.txt \
29+
--no-confirmation \
30+
--no-browser

scripts/release.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)