-
Notifications
You must be signed in to change notification settings - Fork 2
134 lines (115 loc) · 4.93 KB
/
Copy pathmain.yml
File metadata and controls
134 lines (115 loc) · 4.93 KB
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
name: Npm publish
on:
push:
branches:
- main
jobs:
check-files:
runs-on: ubuntu-latest
name: Check files changed
outputs:
changed-files: ${{ toJSON(steps.changed-files-docs.outputs) }}
bump-version: ${{ steps.changed-files-docs.outputs.only_changed == 'false' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files in the docs folder
id: changed-files-docs
env:
MONITORED_PATH: 'website'
run: |
# If pull request, compare the base and head
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
else
# For push event, compare the before and after
BASE_SHA=${{ github.event.before }}
HEAD_SHA=${{ github.event.after }}
# Handle the empty case (like first run or force push)
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
# If it's the first run, use the parent commit of the last commit
BASE_SHA=$(git rev-parse HEAD^)
HEAD_SHA=$(git rev-parse HEAD)
fi
fi
echo "Comparing $BASE_SHA...$HEAD_SHA"
# Get the changed files list - detect monitored path changes
MONITORED_CHANGES=$(git diff --name-status $BASE_SHA $HEAD_SHA | grep -E "^[ACDMRT]\s+${MONITORED_PATH}/" || true)
TOTAL_MONITORED_CHANGES=$(echo "$MONITORED_CHANGES" | grep -v "^$" | wc -l)
# Get all changed files for reference
ALL_CHANGES=$(git diff --name-only $BASE_SHA $HEAD_SHA)
TOTAL_CHANGES=$(echo "$ALL_CHANGES" | grep -v "^$" | wc -l)
# Extract the list of changed files
CHANGED_FILES=$(echo "$MONITORED_CHANGES" | awk '{print $2}')
# Create arrays for changed files
declare -a ALL_FILES_ARRAY
for file in $CHANGED_FILES; do
if [ ! -z "$file" ]; then
ALL_FILES_ARRAY+=("$file")
fi
done
# Convert to JSON using jq
ALL_FILES_JSON=$(printf "%s\n" "${ALL_FILES_ARRAY[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
# Escape quotes for GitHub Actions output
ESCAPED_ALL_FILES=$(echo "$ALL_FILES_JSON" | sed 's/"/\\"/g')
# Determine if only monitored directory changed or other files changed too
if [ $TOTAL_MONITORED_CHANGES -eq 0 ]; then
# No monitored changes
ONLY_CHANGED="true"
elif [ $TOTAL_MONITORED_CHANGES -eq $TOTAL_CHANGES ]; then
# Only monitored files changed
ONLY_CHANGED="true"
else
# Both monitored and other files changed
ONLY_CHANGED="false"
fi
# Debug output
echo "Monitored path: ${MONITORED_PATH}"
echo "Monitored changes: $TOTAL_MONITORED_CHANGES"
echo "Total changes: $TOTAL_CHANGES"
echo "Only monitored changed: $ONLY_CHANGED"
echo "Changed files: $ESCAPED_ALL_FILES"
# Set all outputs to match changed-files format
echo "all_changed_files=$ESCAPED_ALL_FILES" >> $GITHUB_OUTPUT
echo "all_changed_files_count=${#ALL_FILES_ARRAY[@]}" >> $GITHUB_OUTPUT
echo "only_changed=$ONLY_CHANGED" >> $GITHUB_OUTPUT
echo "any_changed=$([[ ${#ALL_FILES_ARRAY[@]} -gt 0 ]] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
publish:
if: needs.check-files.outputs.bump-version == 'true'
runs-on: ubuntu-latest
needs:
- check-files
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_HUB_TOKEN }}
- uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- run: npm add -g @antfu/ni
- run: nci
- name: Publish to npm
run: |
npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}"
pnpm -r --filter "./plugins/*" --filter "./packages/create-app" exec npm publish --access public --no-git-checks
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
- name: Config Git
run: |
git config --local user.name "bot"
git config --local user.email "bot@arcblock.io"
- name: Git Tag
run: |
git tag -a v${{ steps.package-version.outputs.current-version }} -m "chore(release): v${{ steps.package-version.outputs.current-version }}"
git push origin v${{ steps.package-version.outputs.current-version }}
- run: npx conventional-github-releaser -p angular
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}}