-
Notifications
You must be signed in to change notification settings - Fork 13
150 lines (132 loc) · 5.26 KB
/
Copy pathbuild-a-zip.yml
File metadata and controls
150 lines (132 loc) · 5.26 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Build a zip, Comment on PR & Delete a zip on closed
on:
pull_request:
types: [opened, synchronize, ready_for_review, closed, labeled]
branches:
- master
- dev
- next-release
- milestone
paths:
- "src/**"
- "includes/**"
- "ultimate-addons-for-gutenberg.php"
- "package.json"
- "package-lock.json"
- "webpack.config.js"
- ".github/workflows/build-a-zip.yml"
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
env:
ZIP_URL: https://dev.ultimategutenberg.com/wp-content/uploads/uag-gh/
PLUGIN_SLUG: ${{ github.event.repository.name }}
ZIP_NAME: "${{ github.event.repository.name }}.zip"
jobs:
build-zip:
name: "Build a zip and upload to server"
if: ${{ github.event.action != 'closed' && github.event.label.name == 'create zip' }}
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.get_current_branch.outputs.branch_name }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Use desired version of NodeJS
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Extract current branch name
id: get_current_branch
run: echo "branch_name=$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')" >> $GITHUB_OUTPUT
- name: Install dependencies
run: npm ci
- name: Create a build
run: npm run build
- name: Build a package
run: bash ./bin/build-zip.sh
- name: Create branch directory
run: |
cd artifact
mkdir -p ${{ steps.get_current_branch.outputs.branch_name }}
mv ${{ env.ZIP_NAME }} ${{ steps.get_current_branch.outputs.branch_name }}/
- name: Upload a zip to server
uses: burnett01/rsync-deployments@4.1
with:
# switches: -avzr --delete --delete-excluded --exclude-from=".distignore" --include="" --filter=""
switches: -avzr
path: ./artifact/
remote_path: ${{ secrets.SSH_ZIP_PATH }}
remote_host: ${{ secrets.SSH_HOST }}
remote_port: ${{ secrets.SSH_PORT }}
remote_user: ${{ secrets.SSH_USER }}
remote_key: ${{ secrets.SSH_KEY }}
comment-on-pr:
name: Comment on PR with links to plugin ZIPs
if: ${{ github.event.action != 'closed' && github.head_ref && github.head_ref != null && github.event.label.name == 'create zip' }}
runs-on: ubuntu-latest
needs: build-zip
env:
CI: true
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
outputs:
pr_number: ${{ steps.get_pr_number.outputs.pr_number }}
comment_body: ${{ steps.get_comment_body.outputs.body }}
steps:
- name: Get PR number
id: get_pr_number
run: echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
- name: Get comment body
id: get_comment_body
run: |
body="Plugin zip for ${{ github.event.pull_request.head.sha }} is ready :bellhop_bell:!
- Download the plugin [zip](${{ env.ZIP_URL }}${{ needs.build-zip.outputs.branch_name }}/${{ env.ZIP_NAME }})"
body="${body//$'\n'/'%0A'}"
echo "body=$body" >> $GITHUB_OUTPUT
- name: Find an old comment if any
uses: sandeshjangam/comment-actions@v1
id: find_comment
with:
type: find
number: ${{ steps.get_pr_number.outputs.pr_number }}
search_term: Download the plugin [zip]
- name: Delete an old comment
if: ${{ steps.find_comment.outputs.comment_id != '' }}
uses: sandeshjangam/comment-actions@v1
with:
type: delete
comment_id: ${{ steps.find_comment.outputs.comment_id }}
- name: Create a new comment with a download link of plugin zip
uses: sandeshjangam/comment-actions@v1
with:
type: create
number: ${{ steps.get_pr_number.outputs.pr_number }}
body: ${{ steps.get_comment_body.outputs.body }}
reactions: hooray, heart, rocket
clean-zip:
name: "Clean a zip on server"
if: ${{ github.event.action == 'closed' }}
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Extract current branch name
id: get_current_branch
run: |
echo "branch_name=$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')" >> $GITHUB_OUTPUT
echo ${{ steps.get_current_branch.outputs.branch_name }}
- name: Execute a delete command using password
if: ${{ steps.get_current_branch.outputs.branch_name != '' }}
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ${{ secrets.SSH_ZIP_PATH }}
rm -rf ${{ steps.get_current_branch.outputs.branch_name }}