-
Notifications
You must be signed in to change notification settings - Fork 1
264 lines (223 loc) · 9.95 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: Create Release
on:
push:
branches:
- main
- dev
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Set up Lua
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
uses: leafo/gh-actions-lua@v2
with:
luaVersion: "5.1"
- name: Set up LuaRocks
uses: leafo/gh-actions-luarocks@v4
- name: Install dependencies for Lua
run: luarocks install busted
- name: Run Lua tests
run: |
if [ -d "spec" ]; then
busted
elif [ -d "tests" ]; then
busted tests
else
echo "No test directory found. Creating a sample test."
mkdir -p spec
echo "describe('Sample test', function() it('should pass', function() assert.is_true(true) end) end)" > spec/sample_spec.lua
busted
fi
- name: Set up Neovim
run: |
sudo add-apt-repository ppa:neovim-ppa/unstable -y
sudo apt-get update
sudo apt-get install -y neovim
- name: Set up Neovim configuration
run: |
mkdir -p ~/.config/nvim
echo 'require("lazy").setup({' > ~/.config/nvim/init.lua
echo ' "nvim-treesitter/nvim-treesitter",' >> ~/.config/nvim/init.lua
echo ' "nvim-lua/plenary.nvim",' >> ~/.config/nvim/init.lua
echo ' "lewis6991/gitsigns.nvim",' >> ~/.config/nvim/init.lua
echo '})' >> ~/.config/nvim/init.lua
nvim --headless -c 'quitall'
- name: Test horizontal scrolling
run: |
nvim --headless +'lua require("typewriter").setup({ enable_horizontal_scroll = true })' +'autocmd BufEnter * normal! zt' +'qall'
- name: Set up Lua environment
run: echo "${{ github.workspace }}/.lua/bin" >> $GITHUB_PATH
- name: Verify Lua installation
run: lua -v
- name: Determine next version
id: determine_version
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo 'v0.0.0')
echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_OUTPUT
git log ${LATEST_TAG}..HEAD --pretty=format:%s > commits.txt
if grep -q '^BREAKING CHANGE:' commits.txt || grep -q '^[a-zA-Z]\+!:' commits.txt; then
BUMP="major"
elif grep -q '^feat:' commits.txt; then
BUMP="minor"
else
BUMP="patch"
fi
echo "BUMP=${BUMP}" >> $GITHUB_OUTPUT
LATEST_VERSION=${LATEST_TAG#v}
IFS='.' read -ra VERSION_PARTS <<< "$LATEST_VERSION"
MAJOR=${VERSION_PARTS[0]:-0}
MINOR=${VERSION_PARTS[1]:-0}
PATCH=${VERSION_PARTS[2]:-0}
case $BUMP in
major)
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
echo "NEW_VERSION=v${NEW_VERSION}" >> $GITHUB_OUTPUT
# Check if the calculated version already exists
if git rev-parse v$NEW_VERSION >/dev/null 2>&1; then
echo "Version v$NEW_VERSION already exists. Incrementing patch version."
PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "NEW_VERSION=v${NEW_VERSION}" >> $GITHUB_OUTPUT
fi
- name: Generate Changelog
id: get_changelog
run: |
LATEST_TAG=${{ steps.determine_version.outputs.LATEST_TAG }}
CHANGELOG=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s")
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
shell: bash
run: |
NEW_VERSION='${{ steps.determine_version.outputs.NEW_VERSION }}'
CHANGELOG=$(cat << 'EOF'
${{ steps.get_changelog.outputs.CHANGELOG }}
EOF
)
CURRENT_DATE=$(TZ='America/Denver' date +%Y-%m-%d)
REPO_URL="https://github.com/joshuadanpeterson/typewriter.nvim"
format_entry() {
local version=$1
local date=$2
local content=$3
local prev_version=$4
echo "## [$version]($REPO_URL/tree/$version) ($date)"
echo "$content"
echo
echo "[Full Changelog]($REPO_URL/compare/$prev_version...$version)"
echo
}
remove_duplicates() {
echo "$1" | awk '!seen[$0]++'
}
echo "# Changelog" > temp_changelog.md
echo >> temp_changelog.md
# Add new version
NEW_CHANGELOG=$(remove_duplicates "$CHANGELOG")
format_entry "$NEW_VERSION" "$CURRENT_DATE" "$NEW_CHANGELOG" "${{ steps.determine_version.outputs.LATEST_TAG }}" >> temp_changelog.md
prev_version="$NEW_VERSION"
declare -A processed_versions
while IFS= read -r line; do
if [[ $line =~ ^##[[:space:]]+(\[v[0-9]+\.[0-9]+\.[0-9]+\])(.*)$ ]]; then
version="${BASH_REMATCH[1]}"
version="${version:1:-1}"
if [[ -n "${processed_versions[$version]}" ]] || [[ "$version" == "$NEW_VERSION" ]]; then
continue
fi
processed_versions[$version]=1
date_part="${BASH_REMATCH[2]}"
date=$(echo "$date_part" | grep -oP '\(\K[0-9]{4}-[0-9]{2}-[0-9]{2}(?=\))' || echo "Unknown Date")
if [ "$date" != "Unknown Date" ]; then
date=$(TZ='America/Denver' date -d "$date" +%Y-%m-%d)
fi
content=$(sed -n "/^## \[$version\]/,/^## \[v[0-9]/{ /^## \[v[0-9]/d; p; }" CHANGELOG.md)
content=$(echo "$content" | sed '/^\[Full Changelog\]/d' | sed '/^$/N;/^\n$/D')
content=$(remove_duplicates "$content")
format_entry "$version" "$date" "$content" "$prev_version" >> temp_changelog.md
prev_version="$version"
fi
done < CHANGELOG.md
mv temp_changelog.md CHANGELOG.md
if ! grep -q "^# Changelog" CHANGELOG.md || ! grep -q "^## \[v[0-9]\+\.[0-9]\+\.[0-9]\+\]" CHANGELOG.md; then
echo "Error: CHANGELOG.md formatting verification failed"
exit 1
fi
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "docs: update CHANGELOG.md for ${NEW_VERSION} and remove duplicate entries"
git push
- name: Check if release exists
id: check_release
run: |
if git ls-remote --exit-code --tags origin refs/tags/${{ steps.determine_version.outputs.NEW_VERSION }} >/dev/null 2>&1; then
echo "RELEASE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "RELEASE_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
if: steps.check_release.outputs.RELEASE_EXISTS == 'false'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.determine_version.outputs.NEW_VERSION }}
release_name: Release ${{ steps.determine_version.outputs.NEW_VERSION }}
body: |
## Changes in this Release
${{ steps.get_changelog.outputs.CHANGELOG }}
For full changelog, see [CHANGELOG.md](https://github.com/joshuadanpeterson/typewriter.nvim/blob/main/CHANGELOG.md)
## Core Features
- Keeps the cursor centered on the screen while typing or navigating.
- Simple commands to enable, disable, and toggle the typewriter mode.
- Integrates with ZenMode and True Zen for a seamless distraction-free environment.
For more details, please check the [README](https://github.com/joshuadanpeterson/typewriter.nvim/blob/main/README.md).
draft: false
prerelease: false
- name: Update existing release
if: steps.check_release.outputs.RELEASE_EXISTS == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const { NEW_VERSION } = process.env;
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingRelease = releases.data.find(release => release.tag_name === NEW_VERSION);
if (existingRelease) {
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: existingRelease.id,
body: `## Changes in this Release\n\n${changelog}\n\nFor full changelog, see [CHANGELOG.md](https://github.com/joshuadanpeterson/typewriter.nvim/blob/main/CHANGELOG.md)\n\n## Core Features\n- Keeps the cursor centered on the screen while typing or navigating.\n- Simple commands to enable, disable, and toggle the typewriter mode.\n- Integrates with ZenMode and True Zen for a seamless distraction-free environment.\n\nFor more details, please check the [README](https://github.com/joshuadanpeterson/typewriter.nvim/blob/main/README.md).`,
});
console.log(`Updated existing release ${NEW_VERSION}`);
} else {
console.log(`Release ${NEW_VERSION} not found`);
}
env:
NEW_VERSION: ${{ steps.determine_version.outputs.NEW_VERSION }}