-
Notifications
You must be signed in to change notification settings - Fork 14
135 lines (123 loc) · 4.24 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Bump version and create release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Create Release and bump version files
uses: helsingborg-stad/[email protected]
with:
php-version: 8.2
node-version: 20.6.0
build-assets:
needs: ['release']
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Get latest release version
id: get-version
run: |
echo "LATEST_RELEASE=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Update version in package.json
run: |
# Read the latest release version from environment variable
LATEST_VERSION="${{ env.LATEST_RELEASE }}"
# Update the "version" field in package.json using jq
jq --arg version "$LATEST_VERSION" '.version = $version' package.json > temp.json && mv temp.json package.json
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Inject access token in .npmrc
run: |
echo "registry=https://npm.pkg.github.com/helsingborg-stad" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc
- name: Run CI
if: ${{ hashFiles('package.json') != '' && hashFiles('package-lock.json') != '' }}
run: npm ci --no-progress --no-audit
- name: Run build
if: ${{ hashFiles('package-lock.json') != '' && hashFiles('gulp.js') == '' }}
run: npx --yes browserslist@latest --update-db && npm run build
- name: Publish npm package to GHCR
run: npm publish --registry=https://npm.pkg.github.com
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create assets zip
uses: thedoctor0/[email protected]
if: ${{ hashFiles('dist/') != '' }}
with:
type: zip
filename: '../assets.zip'
directory: dist
exclusions: '*.git* /*node_modules/* */source/sass/* */source/js/*'
- name: Upload Assets
uses: helsingborg-stad/[email protected]
if: ${{ hashFiles('assets.zip') != '' }}
with:
artifact: "assets.zip"
gh_token: ${{ secrets.GITHUB_TOKEN }}
release: ${{ env.LATEST_RELEASE }}
repo: ${{ github.repository }}
artifact_mime_type: application/zip
- name: Setup PHP
uses: shivammathur/setup-php@v2
if: ${{ hashFiles('composer.json') != '' }}
with:
tools: composer
php-version: '8.2'
- name: Build PHP
if: ${{ hashFiles('composer.json') != '' }}
run: |
composer install --prefer-dist --no-progress --no-dev
composer dump-autoload
- name: Process removables
run: |
removables=('.git'
'.gitignore'
'.github'
'.gitattributes'
'build.php'
'.npmrc'
'composer.json'
'composer.lock'
'env-example'
'webpack.config.js'
'package-lock.json'
'package.json'
'phpunit.xml.dist'
'README.md'
'gulpfile.js'
'./node_modules/'
'./source/sass/'
'./source/js/'
'LICENSE'
'babel.config.js'
'yarn.lock'
)
for item in ${removables[@]}; do rm -rf $item; done;
- name: Create release zip
uses: thedoctor0/[email protected]
with:
type: zip
filename: 'release.zip'
exclusions: '*.git* /*node_modules/* */source/sass/* */source/js/*'
- name: Upload release
uses: helsingborg-stad/[email protected]
with:
artifact: "release.zip"
gh_token: ${{ secrets.GITHUB_TOKEN }}
release: ${{ env.LATEST_RELEASE }}
repo: ${{ github.repository }}
artifact_mime_type: application/zip