1- name : Bump version and create release
1+ name : Bump version, build and create release
22
33on :
44 push :
5- branches : [main]
5+ branches :
6+ - main
67
78jobs :
89 release :
910 runs-on : ubuntu-latest
10-
11- steps :
12-
13- - name : Checkout
14- uses : actions/checkout@v2
15- with :
16- fetch-depth : 0
17-
18- - name : Create Release and bump version files
19- uses :
helsingborg-stad/[email protected] 20- with :
21- php-version : 8.2
22- node-version : 20.6.0
23- build-assets :
24- needs : ['release']
25- runs-on : ubuntu-latest
2611 permissions :
27- contents : read
12+ contents : write
2813 packages : write
14+
2915 steps :
30- - name : Get latest release version
31- id : get-version
32- run : |
33- echo "LATEST_RELEASE=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')" >> $GITHUB_ENV
3416 - name : Checkout
3517 uses : actions/checkout@v4
3618 with :
3719 fetch-depth : 0
38- - name : Update version in package.json
39- run : |
40- # Read the latest release version from environment variable
41- LATEST_VERSION="${{ env.LATEST_RELEASE }}"
4220
43- # Update the "version" field in package.json using jq
44- jq --arg version "$LATEST_VERSION" '.version = $version' package.json > temp.json && mv temp.json package.json
45- - name : Setup node
46- uses : actions/setup-node@v3
21+ - name : Bump version files (no release yet)
22+ uses : helsingborg-stad/release-wp-plugin-action@main
4723 with :
24+ php-version : 8.2
4825 node-version : 20.6.0
49- - name : Inject access token in .npmrc
50- run : |
51- echo "registry=https://npm.pkg.github.com/helsingborg-stad" >> ~/.npmrc
52- echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc
53- - name : Run CI
54- if : ${{ hashFiles('package.json') != '' && hashFiles('package-lock.json') != '' }}
55- run : npm ci --no-progress --no-audit
56- - name : Run install
57- if : ${{ hashFiles('package.json') != '' && hashFiles('package-lock.json') == '' }}
58- run : npm install --no-progress --no-audit
59- - name : Run build
60- if : ${{ hashFiles('package-lock.json') != '' && hashFiles('gulp.js') == '' }}
61- run : npx --yes browserslist@latest --update-db && npm run build
62- - name : Run gulp
63- if : ${{ hashFiles('package-lock.json') != '' && hashFiles('gulp.js') != '' }}
64- run : gulp
65- - name : Publish npm package to GHCR
66- run : npm publish --registry=https://npm.pkg.github.com
67- env :
68- NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69- - name : Create assets zip
70- uses :
thedoctor0/[email protected] 71- if : ${{ hashFiles('dist/') != '' }}
72- with :
73- type : zip
74- filename : ' ../assets.zip'
75- directory : dist
76- exclusions : ' *.git* /*node_modules/* */source/sass/* */source/js/*'
77- - name : Upload Assets
78- uses :
helsingborg-stad/[email protected] 79- if : ${{ hashFiles('assets.zip') != '' }}
80- with :
81- artifact : " assets.zip"
82- gh_token : ${{ secrets.GITHUB_TOKEN }}
83- release : ${{ env.LATEST_RELEASE }}
84- repo : ${{ github.repository }}
85- artifact_mime_type : application/zip
26+ skip-release : true # custom flag you added
27+
28+ - name : Pull latest main with bumped version
29+ run : |
30+ git fetch origin main
31+ git checkout main
32+ git pull origin main
33+
34+ - name : Extract version
35+ id : version
36+ run : |
37+ VERSION=$(jq -r '.version' package.json)
38+ echo "version=$VERSION" >> $GITHUB_OUTPUT
39+ echo "Detected version: $VERSION"
8640
41+ # --- PHP Build ---
8742 - name : Setup PHP
8843 uses : shivammathur/setup-php@v2
89- if : ${{ hashFiles('composer.json') != '' }}
9044 with :
91- tools : composer
92-
93- - name : Build PHP
94- if : ${{ hashFiles('composer.json') != '' }}
45+ php-version : " 8.2"
46+
47+ - name : Configure npm for GitHub Packages
9548 run : |
96- composer install --prefer-dist --no-progress --no-dev
97- composer dump-autoload
49+ echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
50+ echo "@helsingborg-stad:registry=https://npm.pkg.github.com" >> ~/.npmrc
51+
52+ - name : Run PHP build script
53+ run : php build.php --no-composer --cleanup --release
9854
99- - name : Process removables
55+ - name : Overwrite .gitignore for release branch
10056 run : |
101- removables=('.git'
102- '.gitignore'
103- '.github'
104- '.gitattributes'
105- 'build.php'
106- '.npmrc'
107- 'composer.json'
108- 'composer.lock'
109- 'env-example'
110- 'webpack.config.js'
111- 'package-lock.json'
112- 'package.json'
113- 'phpunit.xml.dist'
114- 'README.md'
115- 'gulpfile.js'
116- './node_modules/'
117- './source/sass/'
118- './source/js/'
119- 'LICENSE'
120- 'babel.config.js'
121- 'yarn.lock'
122- )
123- for item in ${removables[@]}; do rm -rf $item; done;
57+ printf "/*\n!/dist\n!/dist/**\n!/source/php\n!/source/php/**\n" > .gitignore
12458
125- - name : Create release zip
126- uses :
thedoctor0/[email protected] 127- with :
128- type : zip
129- filename : ' release.zip'
130- exclusions : ' *.git* /*node_modules/* */source/sass/* */source/js/*'
131-
132- - name : Upload release
133- uses :
helsingborg-stad/[email protected] 59+ # --- Release Branch Commit ---
60+ - name : Commit and push release branch
61+ run : |
62+ git config user.name "CI Release Bot"
63+ git config user.email "[email protected] " 64+ git checkout -B release
65+ git add -A
66+ git commit -m "Release build from $GITHUB_SHA" || echo "No changes to commit"
67+ git push origin release --force
68+
69+ # --- Tag and create GitHub Release on release branch ---
70+ - name : Create and push tag
71+ run : |
72+ TAG="${{ steps.version.outputs.version }}"
73+ # skip if tag already exists
74+ if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
75+ echo "Tag $TAG already exists, skipping tag creation."
76+ exit 0
77+ fi
78+ git tag "$TAG"
79+ git push origin "$TAG"
80+
81+ - name : Wait for tag propagation
82+ run : sleep 5
83+
84+ - name : Create GitHub Release
85+ uses : ncipollo/release-action@v1
13486 with :
135- artifact : " release.zip"
136- gh_token : ${{ secrets.GITHUB_TOKEN }}
137- release : ${{ env.LATEST_RELEASE }}
138- repo : ${{ github.repository }}
139- artifact_mime_type : application/zip
87+ tag : ${{ steps.version.outputs.version }}
88+ generateReleaseNotes : true
0 commit comments