Skip to content

Commit b87c79a

Browse files
authored
Merge pull request #7 from emacs-tree-sitter/ci/update-bundle-version
ci: Add CI to automatically update the bundle version
2 parents a5d9eac + dc68710 commit b87c79a

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

.github/workflows/get_version.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Get Version
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
version:
7+
description: The latest `tree-sitter-langs` Version
8+
value: ${{ jobs.get-version.outputs.VERSION }}
9+
inputs:
10+
workflow_ref:
11+
description: 'Must be the same as "uses: ...@THIS"'
12+
default: master
13+
required: false
14+
type: string
15+
16+
env:
17+
EMACS_VER: 30.2
18+
19+
jobs:
20+
get-version:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
version: ${{ steps.expose-ver.outputs.VERSION }}
24+
steps:
25+
- uses: jcs090218/setup-emacs@master
26+
with:
27+
version: ${{ env.EMACS_VER }}
28+
29+
- uses: emacs-eask/setup-eask@master
30+
with:
31+
version: 'snapshot'
32+
33+
- uses: actions/checkout@v5
34+
35+
- name: Expose Version
36+
id: expose-ver
37+
run: |
38+
eask install-deps --dev
39+
VERSION=$(eask load scripts/latest-tag.el)
40+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
41+
echo "$VERSION"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Update Bundle Version
2+
3+
on:
4+
schedule:
5+
- cron: '0 * * * *'
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
get-version:
14+
uses: emacs-tree-sitter/treesit-langs/.github/workflows/get_version.yml@master
15+
16+
main:
17+
needs: [get-version]
18+
runs-on: ubuntu-latest
19+
env:
20+
VERSION: ${{ needs.get-version.outputs.version }}
21+
steps:
22+
- uses: actions/checkout@v5
23+
with:
24+
persist-credentials: false
25+
fetch-depth: 0
26+
27+
- name: Expose bundle version
28+
run: |
29+
echo "BUNDLE_VER=${{ env.VERSION }}" >> $GITHUB_ENV
30+
31+
- name: Update Bundle Version
32+
run: |
33+
eask run script update-bundle-version
34+
35+
- name: Create Pull Request
36+
uses: peter-evans/create-pull-request@v6
37+
with:
38+
title: 'Update Bundle Version to ${{ env.VERSION }}'
39+
body: ''
40+
commit-message: 'Update Bundle Version to ${{ env.VERSION }}'
41+
branch: submodules-update
42+
delete-branch: true

Eask

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
(package-file "treesit-langs.el")
1111

1212
(script "test" "echo \"Error: no test specified\" && exit 1")
13+
(script "update-bundle-version" "eask load scripts/update-bundle-version.el")
1314

1415
(source 'gnu)
1516
(source 'melpa)
17+
(source 'jcs-elpa)
1618

1719
(depends-on "emacs" "29.1")
20+
21+
(development
22+
(depends-on "elenv")
23+
(depends-on "github-tags"))

scripts/_prepare.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
;;; _prepare.el --- Prepration -*- lexical-binding: t -*-
2+
;;; Commentary:
3+
;;; Code:
4+
5+
(require 'cl-lib)
6+
(require 'subr-x)
7+
8+
(require 'elenv)
9+
10+
(defun get-latest-tag ()
11+
"Return the latest tag (not including pre-release)."
12+
(require 'github-tags)
13+
(if-let* ((repo "emacs-tree-sitter/tree-sitter-langs")
14+
(response (cdr (github-tags repo)))
15+
(tags (plist-get response :names))
16+
(latest (nth 1 tags))) ; Skip the first one since it's the pre-release!
17+
latest
18+
(user-error "[ERROR] Latest tag not found in repository: %s" repo)))
19+
20+
;; Local Variables:
21+
;; coding: utf-8
22+
;; no-byte-compile: t
23+
;; End:
24+
;;; _prepare.el ends here

scripts/latest-tag.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
;;; latest-tag.el --- Print latest tag -*- lexical-binding: t -*-
2+
;;; Commentary:
3+
;;; Code:
4+
5+
(load-file "./scripts/_prepare.el")
6+
7+
(princ (get-latest-tag))
8+
9+
;; Local Variables:
10+
;; coding: utf-8
11+
;; no-byte-compile: t
12+
;; End:
13+
;;; latest-tag.el ends here

scripts/update-bundle-version.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;;; update-bundle-version.el --- Update the bundle version -*- lexical-binding: t -*-
2+
;;; Commentary:
3+
;;; Code:
4+
5+
(load-file "./scripts/_prepare.el")
6+
7+
(let ((ver (or (getenv "BUNDLE_VER")
8+
"0.1.0")))
9+
(with-current-buffer (find-file "treesit-langs.el")
10+
(goto-char (point-min))
11+
(when (search-forward "(defcustom treesit-langs-bundle-version \"" nil t)
12+
(let ((start (point))
13+
(end (save-excursion (forward-sexp) (point))))
14+
(delete-region start end)
15+
(insert ver)
16+
(save-buffer))
17+
(message "[INFO] Updated the bundle version to `%s`" ver))))
18+
19+
;; Local Variables:
20+
;; coding: utf-8
21+
;; no-byte-compile: t
22+
;; End:
23+
;;; update-bundle-version.el ends here

0 commit comments

Comments
 (0)