Skip to content

Commit 56deeab

Browse files
committed
Add release workflows
1 parent 010dfc5 commit 56deeab

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Check plugin version and tags"
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
jobs:
8+
version-check:
9+
name: "Check version doesn't not already exists."
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- id: set-vars
18+
name: "Set variables from .plugin-data file"
19+
run: |
20+
# Get all data from .plugin-data file
21+
content=`cat ./.plugin-data`
22+
# the following lines are only required for multi line json
23+
content="${content//'%'/'%25'}"
24+
content="${content//$'\n'/'%0A'}"
25+
content="${content//$'\r'/'%0D'}"
26+
# end of optional handling for multi line json
27+
echo "::set-output name=pluginData::$content"
28+
29+
- id: version-check
30+
name: "Check version in .plugin-data is not existing"
31+
run: |
32+
# Check version from .plugin-data
33+
VERSION=${{fromJson(steps.set-vars.outputs.pluginData).version}}
34+
35+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
36+
echo "Tag aleady exists please update the .plugin-data file to good version";
37+
exit 1;
38+
fi

.github/workflows/release.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "Release new TAG"
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build-and-release:
9+
name: "Release new TAG"
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- id: set-vars
18+
name: "Set variable from .plugin-data file"
19+
run: |
20+
# Get all data from .plugin-data file
21+
content=`cat ./.plugin-data`
22+
# the following lines are only required for multi line json
23+
content="${content//'%'/'%25'}"
24+
content="${content//$'\n'/'%0A'}"
25+
content="${content//$'\r'/'%0D'}"
26+
# end of optional handling for multi line json
27+
echo "::set-output name=pluginData::$content"
28+
29+
- id: check-version
30+
name: "Check version does not exists"
31+
run: |
32+
# Get the version from .plugin-data file.
33+
VERSION=${{fromJson(steps.set-vars.outputs.pluginData).version}}
34+
35+
echo "Get Branch tag"
36+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
37+
echo "Tag already exists, stop now";
38+
exit 1;
39+
fi
40+
41+
- id: build-node
42+
name: "Build project CSS and JS"
43+
uses: actions/setup-node@v3
44+
with:
45+
node-version-file: '.nvmrc'
46+
cache: 'npm'
47+
- run: npm install
48+
- run: npm run build
49+
50+
- id: build-php
51+
name: "Build project PHP"
52+
uses: shivammathur/setup-php@v2
53+
with:
54+
php-version: 7.2
55+
- run: composer install --prefer-dist --no-dev -o --ignore-platform-reqs
56+
57+
- id: commit-and-push
58+
name: "Commit and push new TAG"
59+
run: |
60+
# Get the version from .plugin-data file.
61+
VERSION=${{fromJson(steps.set-vars.outputs.pluginData).version}}
62+
63+
echo "Copy .distignore to .gitignore"
64+
cp .distignore .gitignore
65+
66+
echo "Configure git"
67+
git config --local user.email "$(git log --format='%ae' HEAD^!)"
68+
git config --local user.name "$(git log --format='%an' HEAD^!)"
69+
70+
echo "Creating branch"
71+
git checkout -b release/{$VERSION}
72+
73+
echo "Creating tag ${VERSION}"
74+
git add .
75+
git add -u
76+
git commit -m "Release version ${VERSION}"
77+
git tag ${VERSION}
78+
git push --tags
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "Publish New Release on WordPress.org"
2+
on:
3+
release:
4+
types: [ published ]
5+
6+
jobs:
7+
wordpress-release:
8+
name: "New release on WordPress.org"
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
14+
- id: set-vars
15+
name: "Set variables from .plugin-data file"
16+
run: |
17+
# Get all data from .plugin-data file
18+
content=`cat ./.plugin-data`
19+
# the following lines are only required for multi line json
20+
content="${content//'%'/'%25'}"
21+
content="${content//$'\n'/'%0A'}"
22+
content="${content//$'\r'/'%0D'}"
23+
# end of optional handling for multi line json
24+
echo "::set-output name=pluginData::$content"
25+
26+
- id: deploy
27+
name: "WordPress.org Plugin Deploy"
28+
if: "! github.event.release.prerelease"
29+
uses: 10up/action-wordpress-plugin-deploy@stable
30+
env:
31+
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
32+
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
33+
SLUG: ${{fromJson(steps.set-vars.outputs.pluginData).slug}}

0 commit comments

Comments
 (0)