-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (88 loc) · 4.52 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
on:
push:
branches:
- main
jobs:
# This job utilises a marketplace action tag to automatically create a release when a pull request
# is labelled as release:major, release:minor or release:patch (it can also be controlled via commit
# message - see their docs for more info)
#
# Unfortunately it doesn't expose a point at which we can change the files before the Version is
# tagged, so we run it in 'dry-run' mode and expose its outputs for use later if required
check_for_release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.prerelease.outputs.version }}
release_body: ${{ steps.prerelease.outputs.body }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- id: prerelease
uses: rymndhng/release-on-push-action@master
name: Check if we are running a new release
with:
tag_prefix: ""
bump_version_scheme: norelease
dry_run: true
use_github_release_notes: true
# This job only runs if the previous job detects that a new release is required. It checks out the
# main branch of the repo, runs some string replaces via `sed` to bump the version numbers. These
# may be changed to suit your project if required.
#
# @TODO Investigate the possibility of adding a build step between Bump the Version Numbers and
# Create a Github Release. The release action allows for zip artifacts to be uploaded, which may
# be extremely appropriate for distribution.
create_release:
needs: check_for_release
runs-on: ubuntu-latest
if: needs.check_for_release.outputs.version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
# Pretty obvious what this does
- name: Check out the repo
uses: actions/checkout@v3
# This action is used to install composer dependencies.
- name: Install Composer dependencies
uses: php-actions/composer@v6
with:
dev: no
# This step is used to get the current date, which we are going to use in the changelog
- name: Get current date
id: get_date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
# This step runs through the files in the plugin and updates all of the relevant version numbers
# with the number of this release. It also updates the changelog with the current date and then
# commits the changes back to the main branch to the repo.
- name: Bump the version numbers
run: |
echo "Creating release version ${{ needs.check_for_release.outputs.version }}"
sed -i "s/version\":\ \"[0-9]\+\.\?[0-9]*\.\?[0-9]*/version\":\ \"${{ needs.check_for_release.outputs.version }}/g" ./package.json
sed -i "s/version\":\ \"[0-9]\+\.\?[0-9]*\.\?[0-9]*/version\":\ \"${{ needs.check_for_release.outputs.version }}/g" ./update.json
sed -i "s/download\/[0-9]\+\.\?[0-9]*\.\?[0-9]*/download\/${{ needs.check_for_release.outputs.version }}/g" ./update.json
sed -i "s/Version:\ [0-9]\+\.\?[0-9]*\.\?[0-9]*/Version:\ ${{ needs.check_for_release.outputs.version }}/g" ./plugin.php
sed -i "s/\[Unreleased\]/\[Unreleased\]\r\n\r\n## \[${{ needs.check_for_release.outputs.version }}\] ${{steps.get_date.outputs.date}} /g" ./changelog.md
git config user.name "Github Actions"
git config user.email "<>"
git add .
git commit -am "Version Numbering"
git push
# This step creates a zip of the plugin which can be used for installation, and then creates a zip
# of the plugin which can be used by the updater directory. These two need a different file structure
# so we create them separately.
- name: Build required zip artifacts
run: |
zip -r -q ~/plugin_template.zip ./ -x ".git/*" ".github/*" "composer.*" "package.json" "update.json" "DOCKER_ENV" "docker_tag" "*.log"
mkdir -p ./update/plugin_template
unzip ~/plugin_template.zip -d ./update/plugin_template
zip -r -q ~/update.zip ./update
# Finally we create a release in Github, and add the two zip files as artifacts. These can then be
# downloaded by users of the plugin.
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.check_for_release.outputs.version }}
name: ${{ needs.check_for_release.outputs.version }}
body: ${{ needs.check_for_release.outputs.release_body }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "~/plugin_template.zip,~/update.zip"