-
Notifications
You must be signed in to change notification settings - Fork 1
142 lines (120 loc) · 4.9 KB
/
nightly-build.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
---
name: Nightly Build
on:
push:
branches:
- main
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
pages: write
id-token: write
jobs:
build:
name: Nightly Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get current tag for HEAD
run: |
echo "CURRENT_TAG=$(git tag --points-at HEAD)" >> $GITHUB_ENV
- name: Setup PHP
uses: shivammathur/setup-php@v2
if: ${{ env.CURRENT_TAG != 'nightly' }}
with:
php-version: latest
coverage: none
tools: wp-cli
- name: Install latest version of dist-archive-command
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: wp package install wp-cli/dist-archive-command:dev-main
- name: Setup Node
uses: actions/setup-node@v4
if: ${{ env.CURRENT_TAG != 'nightly' }}
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: npm ci
- name: Build plugin
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: npm run build
- name: Update version number
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: |
CURRENT_DATE=$(date +%Y.%-m.%-d)
sed -i -e "s/Version:.*/Version: 0.1.$CURRENT_DATE-${GITHUB_SHA::7}/g" ./media-experiments.php
- name: Create updates information
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: |
CURRENT_DATE=$(date +%Y.%m.%d)
UPDATE=$(cat <<-END
{
"id": "https://swissspidy.github.io/media-experiments/update.json",
"slug": "media-experiments",
"version": "0.1.$CURRENT_DATE-${GITHUB_SHA::7}",
"url": "https://github.com/swissspidy/media-experiments",
"package": "https://swissspidy.github.io/media-experiments/nightly.zip",
"tested": "6.6",
"requires_php": "8.0",
"autoupdate": true
}
END
)
echo $UPDATE > update.json
- name: Create ZIP file
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: wp dist-archive . ./media-experiments.zip
- name: Prepare GitHub Pages
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: |
mkdir -p _site
mv update.json _site/update.json
cp ./media-experiments.zip _site/nightly.zip
- name: Upload artifact
if: ${{ env.CURRENT_TAG != 'nightly' }}
uses: actions/upload-pages-artifact@v3
- name: Delete existing release
uses: actions/github-script@v7
if: ${{ env.CURRENT_TAG != 'nightly' }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
const response = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: "nightly"
});
github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: response.data.id,
});
} catch {}
- name: Tag current commit
if: ${{ env.CURRENT_TAG != 'nightly' }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "swissspidy-bot"
git push origin :refs/tags/nightly
git tag -f nightly
git push origin --tags
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4