-
-
Notifications
You must be signed in to change notification settings - Fork 16
159 lines (144 loc) · 5.44 KB
/
version.yaml
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
---
name: Version check 🏁
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
workflow_dispatch:
workflow_call:
inputs:
package-subdirectory:
description: Subdirectory in the repository, where the R package is located.
required: false
type: string
default: "."
concurrency:
group: version-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
version:
name: Version check 🏁
runs-on: ubuntu-latest
if: >
!contains(github.event.commits[0].message, '[skip version]')
&& github.event.pull_request.draft == false
steps:
- name: Get branch names 🌿
id: branch-name
uses: tj-actions/branch-names@v7
- name: Checkout repo (PR) 🛎
uses: actions/[email protected]
if: github.event_name == 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout repo 🛎
uses: actions/[email protected]
if: github.event_name != 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
- name: Check commit message 💬
run: |
git config --global --add safe.directory $(pwd)
export head_commit_message="$(git show -s --format=%B | tr '\r\n' ' ' | tr '\n' ' ')"
echo "head_commit_message = $head_commit_message"
if [[ $head_commit_message == *"$SKIP_INSTRUCTION"* ]]; then
echo "Skip instruction detected - cancelling the workflow."
exit 1
fi
shell: bash
env:
SKIP_INSTRUCTION: "[skip version]"
- name: NEWS.md and DESCRIPTION Version check 🏁
run: |
DESC_VERSION=$(awk -F: '/Version:/{gsub(/[ ]+/,"") ; print $2}' DESCRIPTION | tr -d '\n' | xargs)
NEWS_VERSION=$(awk '/^#+ /{print $3,$4; exit}' NEWS.md | tr -d '\n' | xargs)
DESC_DEV_VERSION=$(echo $DESC_VERSION | awk -F '.' '{print $NF}')
echo "NEWS.md version: $NEWS_VERSION"
echo "DESCRIPTION version: $DESC_VERSION"
if test $DESC_VERSION = $NEWS_VERSION
then {
echo "NEWS.md and DESCRIPTION have the same version 🎉"
exit 0
}
fi
if [[ $DESC_DEV_VERSION -ge 9000 && "${NEWS_VERSION}" == "(development version)" ]]
then {
echo "NEWS.md and DESCRIPTION file versions are okay as package is in development mode."
echo "All is okay 🆗"
exit 0
}
fi
echo "🙈 NEWS.md and DESCRIPTION have different versions!"
echo "🙏 Please fix this."
exit 1
shell: bash
working-directory: ${{ inputs.package-subdirectory }}
emoji:
name: Emoji in NEWS.md 📰
runs-on: ubuntu-latest
if: >
!contains(github.event.commits[0].message, '[skip version]')
&& github.event.pull_request.draft == false
steps:
- name: Get branch names 🌿
id: branch-name
uses: tj-actions/branch-names@v7
- name: Checkout repo (PR) 🛎
uses: actions/[email protected]
if: github.event_name == 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout repo 🛎
uses: actions/[email protected]
if: github.event_name != 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
- name: Check commit message 💬
run: |
git config --global --add safe.directory $(pwd)
export head_commit_message="$(git show -s --format=%B | tr '\r\n' ' ' | tr '\n' ' ')"
echo "head_commit_message = $head_commit_message"
if [[ $head_commit_message == *"$SKIP_INSTRUCTION"* ]]; then
echo "Skip instruction detected - cancelling the workflow."
exit 1
fi
shell: bash
env:
SKIP_INSTRUCTION: "[skip version]"
- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install the regex package 📦
uses: insightsengineering/pip-action@v2
with:
packages: regex
- name: Check for emojis in NEWS.md 🏁
run: |
import regex
import sys
with open('NEWS.md', 'r') as file:
text = file.read()
lines = text.split('\n')
emoji_pattern = regex.compile(r"(?![\d\p{P}])\p{Emoji}")
for line_num, line in enumerate(lines, start=1):
matches = [(match.group(), match.start(), match.end()) for match in emoji_pattern.finditer(line)]
for emoji, start, end in matches:
print(f"Emoji: {emoji} | Line: {line_num} | Start: {start} | End: {end}")
if matches:
print("🚨 Emojis were found in the NEWS.md file! Please remove them 🙏")
print("ℹ️ Refer to https://github.com/insightsengineering/tern.gee/issues/37#issue-1714621201 for more information")
sys.exit(1)
print("🥰 No emojis found in the NEWS.md, good to go!")
shell: python
working-directory: ${{ inputs.package-subdirectory }}