-
Notifications
You must be signed in to change notification settings - Fork 3
112 lines (96 loc) · 3.94 KB
/
release.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
name: Publish release
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Parse version number from style.css
id: get_version
run: |
VERSION=$(grep -oP '(?<=^ \* Version: ).*' style.css | head -1)
echo "Version found: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Fetch latest tag
id: fetch_latest_tag
run: |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "none")
echo "Latest tag: $LATEST_TAG"
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Compare versions and decide if a new tag is needed
id: compare_versions
run: |
if [ "$LATEST_TAG" = "none" ]; then
echo "No previous tag found. Proceeding with new tag and release."
echo "RELEASE_NEEDED=true" >> $GITHUB_ENV
elif [ "$(printf '%s\n' "$VERSION" "$LATEST_TAG" | sort -V | head -n1)" != "$VERSION" ]; then
echo "New version detected. Proceeding with new tag and release."
echo "RELEASE_NEEDED=true" >> $GITHUB_ENV
else
echo "No new version. Skipping release."
echo "RELEASE_NEEDED=false" >> $GITHUB_ENV
fi
- name: Stop job if no release needed
if: env.RELEASE_NEEDED == 'false'
run: |
echo "Skipping further steps as no new release is needed."
continue-on-error: false
# Dependency Setup and Build Steps - Only Run if Release is Needed
- name: Set up PHP
if: env.RELEASE_NEEDED == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: curl
coverage: none
- name: Set up Node
if: env.RELEASE_NEEDED == 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
if: env.RELEASE_NEEDED == 'true'
run: |
composer install --no-dev --optimize-autoloader
npm install
npx browserslist@latest --update-db
npx tailwindcss -i assets/style.css -o dist/style.css --minify
npx tailwindcss -i assets/editor.css -o dist/editor.css --minify
- name: Tag and release if needed
if: env.RELEASE_NEEDED == 'true'
run: |
git tag ${{ env.VERSION }}
git push origin ${{ env.VERSION }}
echo "Tag created and pushed: ${{ env.VERSION }}"
- name: Prepare subdirectory for release
if: env.RELEASE_NEEDED == 'true'
run: |
mkdir -p release # Ensure the directory is created
rsync -av --progress . ./release --exclude release --exclude .git --exclude .github --exclude node_modules --exclude .gitignore
- name: List contents of release directory for debugging
if: env.RELEASE_NEEDED == 'true'
run: |
echo "Listing contents of release directory:"
ls -la ./release
- name: Compress release directory contents
if: env.RELEASE_NEEDED == 'true'
run: |
echo "Compressing contents of release directory..."
cd release
zip -r ../streekomroep-wp-theme-${{ env.VERSION }}.zip ./*
- name: List contents of current directory after compression
if: env.RELEASE_NEEDED == 'true'
run: |
echo "Listing contents of current directory:"
ls -la
- name: Create GitHub Release and upload compressed file
if: env.RELEASE_NEEDED == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Uploading streekomroep-wp-theme-${{ env.VERSION }}.zip to GitHub release..."
gh release create ${{ env.VERSION }} streekomroep-wp-theme-${{ env.VERSION }}.zip --title "${{ env.VERSION }}" --notes "Automated release for version ${{ env.VERSION }}"