forked from Automattic/themes
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (110 loc) · 4.4 KB
/
version-bump.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
name: Version bump themes
on:
workflow_dispatch:
inputs:
theme-slug:
description: 'Theme slug'
required: false
default: 'all'
jobs:
version-bump:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: trunk
- name: Create branch
id: create-branch
run: |
BRANCH_NAME="automated-version-bump/${{ github.run_number }}"
git checkout -b $BRANCH_NAME
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 19
- name: Install node dependencies
run: npm install
- name: Version bump
id: version-bump
run: |
if [ "${{ github.event.inputs.theme-slug }}" == 'all' ]; then
npm run deploy:version-bump
else
# Check if theme exists
theme_exists=false
target_theme_slug=${{ github.event.inputs.theme-slug }}
# Loop through each subdirectory in the themes directory
for dir in ./*/; do
# Get the name of the directory (theme name)
theme_dir_name=$(basename "$dir")
# Check if the directory name matches the target theme name and if it contains a style.css file
if [[ "$theme_dir_name" == "$target_theme_slug" && -f "$dir/style.css" ]]; then
theme_exists=true
fi
done
# Error out if theme does not exist
if [ "$theme_exists" == false ]; then
echo "Theme `${{ github.event.inputs.theme-slug }}` does not exist"
exit 1
fi
npm run deploy:version-bump -- ${{ github.event.inputs.theme-slug }}
fi
- name: Check if there are changes
id: check-changes
run: |
if [ "$(git diff --cached --name-only)" ]; then
echo "HAS_CHANGES=true" >> $GITHUB_ENV
# Get list of changed directory names for staged changes
changed_dirs=$(git diff --cached --name-only | xargs -I {} dirname {} | sort | uniq)
# Initialize an array for CHANGED_THEMES
changed_themes=()
# Iterate over the changed directories
for dir in $changed_dirs; do
if [ -f "$dir/style.css" ]; then
# Append the directory to changed_themes array
changed_themes+=("$dir")
fi
done
# Join array elements into a string
CHANGED_THEMES=$(IFS=,; echo "${changed_themes[*]}")
echo "CHANGED_THEMES=$CHANGED_THEMES" >> $GITHUB_ENV
echo "Themes with changes: $CHANGED_THEMES"
else
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi
- name: Commit changes
if: env.HAS_CHANGES == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "Version bump & changelog update" --no-verify
git push --set-upstream origin ${{ env.BRANCH_NAME }}
- name: Create Pull Request
if: env.HAS_CHANGES == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGED_THEMES: ${{ env.CHANGED_THEMES }}
run: |
echo "Creating PR for themes: $CHANGED_THEMES"
THEMES_LIST=$(echo "$CHANGED_THEMES" | tr ',' '\n')
PR_BODY=$(cat <<-EOF
## [Automation] Themes Version Bump
This PR was automatically created by the version bump workflow.
### Updated Themes
The following themes are being updated due to changes since the last git tag:
$THEMES_LIST
### Why These Updates?
This script bumps the version of themes that have changes since the last git tag. This ensures that any updates or fixes are properly versioned and deployed.
### Disclaimer
This is an automated process. Please review the changes carefully.
EOF
)
gh pr create \
--title "[Automation] Themes version bump" \
--base trunk \
--head ${{ env.BRANCH_NAME }} \
--body "$PR_BODY"