feat: add r-hub workflow #1259
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 }} |