-
Notifications
You must be signed in to change notification settings - Fork 41
217 lines (214 loc) · 9.97 KB
/
zip.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: 'Package Zip'
on:
pull_request:
workflow_dispatch:
inputs:
final:
description: 'Zip type: 0 = dev, 1 = production'
required: false
default: '0'
slack_channel:
description: 'Slack channel ID to post to'
required: false
slack_thread:
description: 'Slack thread to post to'
required: false
jobs:
zip:
runs-on: ubuntu-latest
steps:
- name: If a pull_request, set final to 0
if: github.event_name == 'pull_request'
run: |
echo "JOB_FINAL=0" >> $GITHUB_ENV
echo "JOB_BRANCH=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
- name: If a workflow_dispatch, set final based on input
if: github.event_name == 'workflow_dispatch'
run: |
echo "JOB_FINAL=${{ github.event.inputs.final }}" >> $GITHUB_ENV
branch=$(echo "${{ github.ref }}" | sed -r "s|refs/heads/||" | sed -r "s|refs/tags/||")
echo "JOB_BRANCH=${branch}" >> $GITHUB_ENV
- name: Setup branch for consumption in subsequent steps
id: settings
run: |
echo "branch=${JOB_BRANCH}" >> $GITHUB_OUTPUT
# -----------------------------------------------------------------------------
# Setup SSH keys and known_hosts
# ------------------------------------------------------------------------------
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.GH_ACTIONS_SSH_KEY }}
name: id_rsa
known_hosts: github.com
# ------------------------------------------------------------------------------
# Checkout the repo
# ------------------------------------------------------------------------------
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
token: ${{ secrets.GH_BOT_TOKEN }}
submodules: recursive
ref: ${{ steps.settings.outputs.branch }}
# ------------------------------------------------------------------------------
# Setup Node.
# ------------------------------------------------------------------------------
- name: Check for .nvmrc file
id: check-nvmrc
run: echo "::set-output name=exists::$(test -f ${{ github.workspace }}/.nvmrc && echo 'true' || echo 'false')"
- uses: actions/setup-node@v3
if: steps.check-nvmrc.outputs.exists == 'true'
with:
node-version-file: '.nvmrc'
cache: 'npm'
cache-dependency-path: package-lock.json
# ------------------------------------------------------------------------------
# Checkout tut
# ------------------------------------------------------------------------------
- name: Checkout tut
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_BOT_TOKEN }}
repository: the-events-calendar/tut
ref: main
path: tut
fetch-depth: 1
- name: Checkout jenkins-scripts
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_BOT_TOKEN }}
repository: the-events-calendar/jenkins-scripts
ref: main
path: jenkins-scripts
fetch-depth: 1
# ------------------------------------------------------------------------------
# Determine if we need to zip
# ------------------------------------------------------------------------------
- name: Generate Zip Filename
id: file_name
working-directory: .
run: |
REPO_ORG=$GITHUB_ACTOR
REPO_NAME=$( echo $GITHUB_REPOSITORY | sed "s/the-events-calendar\///")
MAIN_FILE=$(jq ".plugins[] | select( .name | test(\"$REPO_NAME\") ) | .main" tut/tut.json | sed 's/"//g' | head -n 1 )
VERSION_LINE=$(jq ".plugins[] | select( .name | test(\"$REPO_NAME\") ) | .version" tut/tut.json | sed 's/"//g' | head -n 1)
ZIP_NAME=$(jq "._zipname" package.json | sed 's/"//g' )
VERSION=$(grep -r "$VERSION_LINE" $MAIN_FILE | head -n 1 | sed -r "s/.*${VERSION_LINE}[^']*'([^']*)'.*/\1/")
HASH=$(git rev-parse --short=8 HEAD)
TIMESTAMP=$(git --no-pager show -s --format=%ct HEAD)
FILENAME="${ZIP_NAME}.${VERSION}-dev-${TIMESTAMP}-${HASH}.zip"
if [ "${JOB_FINAL}" == "1" ]; then
FILENAME="${ZIP_NAME}.${VERSION}.zip"
fi
echo "value=${FILENAME}" >> $GITHUB_OUTPUT
echo $FILENAME
- name: Check if zip already exists
uses: the-events-calendar/action-s3-utility@main
if: github.event.inputs.final != '1'
id: s3_zip
continue-on-error: true
env:
S3_BUCKET: ${{ secrets.PACKAGED_ZIP_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.PACKAGED_ZIP_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
COMMAND: exists
FILE: ${{ steps.file_name.outputs.value }}
# ------------------------------------------------------------------------------
# Prepare our cache directories
# ------------------------------------------------------------------------------
- name: Get Composer Cache Directory
if: steps.s3_zip.outcome != 'success'
id: get-composer-cache-dir
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v2
if: steps.s3_zip.outcome != 'success'
id: composer-cache
with:
path: ${{ steps.get-composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
# ------------------------------------------------------------------------------
# Ensure composer permissions
# ------------------------------------------------------------------------------
- name: Set composer folder permissions
run: |
sudo chown $USER $HOME/.composer
# ------------------------------------------------------------------------------
# Initialize tut
# ------------------------------------------------------------------------------
- name: Set up tut env vars
if: steps.s3_zip.outcome != 'success'
run: |
echo "TUT_BIN=${GITHUB_WORKSPACE}/tut/tut" >> $GITHUB_ENV
- name: Make tut envfile
if: steps.s3_zip.outcome != 'success'
working-directory: ./tut
run: |
touch .env
echo "GITHUB_USER=${{ secrets.GH_BOT_USER }}" >> .env
echo "GITHUB_OAUTH_TOKEN=${{ secrets.GH_BOT_token }}" >> .env
- name: Install tut composer dependencies
if: steps.s3_zip.outcome != 'success'
working-directory: ./tut
run: |
composer install --no-dev -o --ignore-platform-reqs
- name: Install jenkins-scripts composer dependencies
working-directory: ./jenkins-scripts
run: |
composer install --no-dev -o --ignore-platform-reqs
cp script-config-sample.yml script-config.yml
# ------------------------------------------------------------------------------
# Zip
# ------------------------------------------------------------------------------
- name: Package the plugin into a zip
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
id: zip
if: steps.s3_zip.outcome != 'success'
working-directory: ../
run: |
REPO_ORG=$GITHUB_ACTOR
REPO_NAME=$( echo $GITHUB_REPOSITORY | sed "s/the-events-calendar\///")
mkdir zip
if [ "${JOB_FINAL}" == "1" ]; then
output=$($TUT_BIN package --plugin=$REPO_NAME --branch="${{ steps.settings.outputs.branch }}" --ignore-view-versions --output=./zip --final -v)
else
output=$($TUT_BIN package --plugin=$REPO_NAME --branch="${{ steps.settings.outputs.branch }}" --ignore-view-versions --output=./zip -v)
fi
echo "$output"
touch ${GITHUB_WORKSPACE}/results.txt
echo "$output" > ${GITHUB_WORKSPACE}/results.txt
mv zip ${GITHUB_WORKSPACE}/zip
- uses: the-events-calendar/action-s3-utility@main
if: steps.s3_zip.outcome != 'success'
with:
args: --acl public-read --follow-symlinks
env:
S3_BUCKET: ${{ secrets.PACKAGED_ZIP_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.PACKAGED_ZIP_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
COMMAND: sync
SOURCE_DIR: /github/workspace/zip
- name: Maybe prep data for Slack message
if: github.event_name == 'workflow_dispatch' && github.event.inputs.slack_channel != '' && github.event.inputs.slack_thread != '' && steps.s3_zip.outcome == 'success'
working-directory: ../
run: |
touch ${GITHUB_WORKSPACE}/results.txt
echo "Packaging results" >> ${GITHUB_WORKSPACE}/results.txt
echo "-----------------" >> ${GITHUB_WORKSPACE}/results.txt
echo "" >> ${GITHUB_WORKSPACE}/results.txt
echo "Successfully packaged:" >> ${GITHUB_WORKSPACE}/results.txt
echo "* ./zip/\"${{ steps.file_name.outputs.value }}\"" >> ${GITHUB_WORKSPACE}/results.txt
echo "" >> ${GITHUB_WORKSPACE}/results.txt
- name: Maybe notify in Slack
if: github.event_name == 'workflow_dispatch' && github.event.inputs.slack_channel != '' && github.event.inputs.slack_thread != ''
working-directory: ../
run: |
php ${GITHUB_WORKSPACE}/jenkins-scripts/mt-jenkins package:send-results --channel ${{ github.event.inputs.slack_channel }} --ts ${{ github.event.inputs.slack_thread }} --results-file "${GITHUB_WORKSPACE}/results.txt" --slack-token ${{ secrets.SLACK_TOKEN }} --build-url https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}