Skip to content

Commit

Permalink
fix: 修复 commit msg 特殊字符报错 (#15)
Browse files Browse the repository at this point in the history
* fix: 修复 commit msg 特殊字符报错

* 删除所有特殊字符

* 删除所有特殊字符

* 删除所有特殊字符

* 删除所有特殊字符

* 1

* 2

* 3

* 3

* test 1

* test 2

* test 3

* test 3

* test 4

* test 5

* test 6

* test 7

* test 8

* test 10

* test 10

* test 11

* test 12

* test 13

* test 14

* test 15

* test 16

* test 17

Environment variable formatting
  • Loading branch information
jefferyjob authored Oct 14, 2024
1 parent b63ddeb commit 7a471e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
21 changes: 15 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@ inputs:
runs:
using: 'composite'
steps:
- name: Auto get env
- name: Environment variable formatting
shell: bash
env:
# pull request
PR_BRANCH: ${{ github.head_ref }}
PR_COMMIT_MESSAGE: ${{ github.event.pull_request.title }}
# commit
BRANCH: ${{ github.ref_name }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
COMMIT_MESSAGE=$(echo "${{ github.event.pull_request.title }}" | tr -d '\n')
COMMIT_MESSAGE="PR: $COMMIT_MESSAGE"
BRANCH="$PR_BRANCH"
COMMIT_MESSAGE="PR: $PR_COMMIT_MESSAGE"
else
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
COMMIT_MESSAGE=$(echo "${{ github.event.head_commit.message }}" | tr -d '\n')
BRANCH="$BRANCH"
COMMIT_MESSAGE="$COMMIT_MESSAGE"
fi
COMMIT_MESSAGE=$(printf "%s" "$COMMIT_MESSAGE" | head -n 1 | tr -d '"()\n')
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
- name: Notify actions
Expand Down
12 changes: 6 additions & 6 deletions notify.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -e

NOTICE_TYPE="$1"
MSG_TYPE="$2"

Expand Down Expand Up @@ -33,17 +34,16 @@ print_env() {
echo "--------------------------------------------------------------------------"
echo " Shell Notification < Initialization Parameters >"
echo "--------------------------------------------------------------------------"
echo " NOTICE_TYPE: $NOTICE_TYPE"
echo " MSG_TYPE: $MSG_TYPE"
echo "--------------------------------------------------------------------------"
echo " STATUS: $STATUS"
echo " REPO: $REPO"
echo " REPO_URL: $REPO_URL"
echo " BRANCH: $BRANCH"
echo " COMMIT_USER: $COMMIT_USER"
echo " COMMIT_MESSAGE: $COMMIT_MESSAGE"
echo " WORKFLOW_URL: $WORKFLOW_URL"
echo " TRIGGER_TIME: $TRIGGER_TIME"
echo "--------------------------------------------------------------------------"
echo " NOTICE_TYPE: $NOTICE_TYPE"
echo " MSG_TYPE: $MSG_TYPE"
echo "--------------------------------------------------------------------------"
}

Expand Down Expand Up @@ -71,8 +71,8 @@ if [[ "$MSG_TYPE" != "text" && "$MSG_TYPE" != "markdown" && "$MSG_TYPE" != "card
exit 1
fi

# 环境变量
COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE" | tr -d '\n')
# 用户提交的 commit message 消息特殊字符处理
COMMIT_MESSAGE=$(printf "%s" "$COMMIT_MESSAGE" | head -n 1 | tr -d '"()\n')

check_param() {
local param_name="$1"
Expand Down

0 comments on commit 7a471e6

Please sign in to comment.