Skip to content

Commit c0bdb4d

Browse files
First pass at getting a zipignore working (#34)
Co-authored-by: Neil Miller <neil@pie.co.de>
1 parent 1665cb6 commit c0bdb4d

File tree

2 files changed

+106
-76
lines changed

2 files changed

+106
-76
lines changed

.github/workflows/release.yml

Lines changed: 98 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,107 @@
1-
name: Create a Release if required
1+
name: Maybe Create a Release
22

33
on:
44
push:
55
branches:
66
- main
77

88
jobs:
9-
# This job utilises a marketplace action tag to automatically create a release when a pull request
10-
# is labelled as release:major, release:minor or release:patch (it can also be controlled via commit
11-
# message - see their docs for more info)
12-
#
13-
# Unfortunately it doesn't expose a point at which we can change the files before the Version is
14-
# tagged, so we run it in 'dry-run' mode and expose its outputs for use later if required
15-
check_for_release:
16-
runs-on: ubuntu-latest
17-
outputs:
18-
version: ${{ steps.prerelease.outputs.version }}
19-
release_body: ${{ steps.prerelease.outputs.body }}
20-
env:
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22-
steps:
23-
- id: prerelease
24-
uses: rymndhng/release-on-push-action@master
25-
name: Check if we are running a new release
26-
with:
27-
tag_prefix: ""
28-
bump_version_scheme: norelease
29-
dry_run: true
30-
use_github_release_notes: true
31-
# This job only runs if the previous job detects that a new release is required. It checks out the
32-
# main branch of the repo, runs some string replaces via `sed` to bump the version numbers. These
33-
# may be changed to suit your project if required.
34-
#
35-
# @TODO Investigate the possibility of adding a build step between Bump the Version Numbers and
36-
# Create a Github Release. The release action allows for zip artifacts to be uploaded, which may
37-
# be extremely appropriate for distribution.
38-
create_release:
39-
needs: check_for_release
40-
runs-on: ubuntu-latest
41-
if: needs.check_for_release.outputs.version
42-
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
steps:
45-
- name: Check out the repo
46-
uses: actions/checkout@v3
47-
48-
- name: Install Composer dependencies
49-
uses: php-actions/composer@v6
50-
with:
51-
dev: no
9+
# This job utilises a marketplace action tag to automatically create a release when a pull request
10+
# is labelled as release:major, release:minor or release:patch (it can also be controlled via commit
11+
# message - see their docs for more info)
12+
#
13+
# Unfortunately it doesn't expose a point at which we can change the files before the Version is
14+
# tagged, so we run it in 'dry-run' mode and expose its outputs for use later if required
15+
check_for_release:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version: ${{ steps.prerelease.outputs.version }}
19+
release_body: ${{ steps.prerelease.outputs.body }}
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
steps:
23+
- id: prerelease
24+
uses: rymndhng/release-on-push-action@master
25+
name: Check if we are running a new release
26+
with:
27+
tag_prefix: ""
28+
bump_version_scheme: norelease
29+
dry_run: true
30+
use_github_release_notes: true
31+
# This job only runs if the previous job detects that a new release is required. It checks out the
32+
# main branch of the repo, runs some string replaces via `sed` to bump the version numbers. These
33+
# may be changed to suit your project if required.
34+
#
35+
# @TODO Investigate the possibility of adding a build step between Bump the Version Numbers and
36+
# Create a Github Release. The release action allows for zip artifacts to be uploaded, which may
37+
# be extremely appropriate for distribution.
38+
create_release:
39+
needs: check_for_release
40+
runs-on: ubuntu-latest
41+
if: needs.check_for_release.outputs.version
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
steps:
45+
- name: Check out the repo
46+
uses: actions/checkout@v3
47+
48+
- name: Install Composer dependencies
49+
uses: php-actions/composer@v6
50+
with:
51+
dev: no
52+
53+
- name: Get current date
54+
id: get_date
55+
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
56+
57+
- name: Bump the version numbers
58+
run: |
59+
echo "Creating release version ${{ needs.check_for_release.outputs.version }}"
60+
sed -i "s/version\":\ \"[0-9]\+\.\?[0-9]*\.\?[0-9]*/version\":\ \"${{ needs.check_for_release.outputs.version }}/g" ./package.json
61+
sed -i "s/version\":\ \"[0-9]\+\.\?[0-9]*\.\?[0-9]*/version\":\ \"${{ needs.check_for_release.outputs.version }}/g" ./update.json
62+
sed -i "s/download\/[0-9]\+\.\?[0-9]*\.\?[0-9]*/download\/${{ needs.check_for_release.outputs.version }}/g" ./update.json
63+
sed -i "s/Version:\ [0-9]\+\.\?[0-9]*\.\?[0-9]*/Version:\ ${{ needs.check_for_release.outputs.version }}/g" ./${{ github.event.repository.name }}.php
64+
sed -i "s/Version:\ [0-9]\+\.\?[0-9]*\.\?[0-9]*/Version:\ ${{ needs.check_for_release.outputs.version }}/g" ./${{ github.event.repository.name }}-mu.php
65+
sed -i "s/\[Unreleased\]/\[Unreleased\]\r\n\r\n## \[${{ needs.check_for_release.outputs.version }}\] ${{steps.get_date.outputs.date}} /g" ./changelog.md
66+
git config user.name "Github Actions"
67+
git config user.email "<>"
68+
git add .
69+
git commit -am "Version Numbering"
70+
git push
71+
72+
- name: Check for ignore file
73+
id: check_files
74+
uses: andstor/file-existence-action@v2
75+
with:
76+
files: ".zipignore"
5277

53-
- name: Get current date
54-
id: get_date
55-
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
56-
57-
- name: Bump the version numbers
58-
run: |
59-
echo "Creating release version ${{ needs.check_for_release.outputs.version }}"
60-
sed -i "s/version\":\ \"[0-9]\+\.\?[0-9]*\.\?[0-9]*/version\":\ \"${{ needs.check_for_release.outputs.version }}/g" ./package.json
61-
sed -i "s/version\":\ \"[0-9]\+\.\?[0-9]*\.\?[0-9]*/version\":\ \"${{ needs.check_for_release.outputs.version }}/g" ./update.json
62-
sed -i "s/download\/[0-9]\+\.\?[0-9]*\.\?[0-9]*/download\/${{ needs.check_for_release.outputs.version }}/g" ./update.json
63-
sed -i "s/Version:\ [0-9]\+\.\?[0-9]*\.\?[0-9]*/Version:\ ${{ needs.check_for_release.outputs.version }}/g" ./${{ github.event.repository.name }}.php
64-
sed -i "s/Version:\ [0-9]\+\.\?[0-9]*\.\?[0-9]*/Version:\ ${{ needs.check_for_release.outputs.version }}/g" ./${{ github.event.repository.name }}-mu.php
65-
sed -i "s/\[Unreleased\]/\[Unreleased\]\r\n\r\n## \[${{ needs.check_for_release.outputs.version }}\] ${{steps.get_date.outputs.date}} /g" ./changelog.md
66-
git config user.name "Github Actions"
67-
git config user.email "<>"
68-
git add .
69-
git commit -am "Version Numbering"
70-
git push
78+
- name: File exists
79+
if: steps.check_files.outputs.files_exists == 'true'
80+
shell: bash
81+
# Only runs if all of the files exists
82+
run: |
83+
sed -i '/^[[:space:]]*$/d' .zipignore
84+
sed 's/^/${{ github.event.repository.name }}\//' .zipignore > ../.zipignore
7185
72-
# This step creates a zip of the plugin which can be used for installation, and by the plugin updater.
73-
- name: Build required zip artifact
74-
run: |
75-
cd ../
76-
zip -r -q ~/${{ github.event.repository.name }}.zip ./${{ github.event.repository.name }} -x ".git/*" ".github/*" "composer.*" "package.json" "update.json" "DOCKER_ENV" "docker_tag" "*.log"
77-
78-
- name: Create a GitHub release
79-
uses: ncipollo/release-action@v1
80-
with:
81-
tag: ${{ needs.check_for_release.outputs.version }}
82-
name: ${{ needs.check_for_release.outputs.version }}
83-
body: ${{ needs.check_for_release.outputs.release_body }}
84-
token: ${{ secrets.GITHUB_TOKEN }}
85-
artifacts: "~/${{ github.event.repository.name }}.zip"
86+
- name: File does not exist
87+
if: steps.check_files.outputs.files_exists != 'true'
88+
shell: bash
89+
# Only runs if any of the files does not exist
90+
run: |
91+
touch ../.zipignore
92+
93+
# This step creates a zip of the plugin which can be used for installation, and by the plugin updater.
94+
- name: Build required zip artifact
95+
run: |
96+
cd ../
97+
zip -r -q ~/${{ github.event.repository.name }}.zip ./${{ github.event.repository.name }} -x@.zipignore
98+
ls -la ~/
99+
100+
- name: Create a GitHub release
101+
uses: ncipollo/release-action@v1
102+
with:
103+
tag: ${{ needs.check_for_release.outputs.version }}
104+
name: ${{ needs.check_for_release.outputs.version }}
105+
body: ${{ needs.check_for_release.outputs.release_body }}
106+
token: ${{ secrets.GITHUB_TOKEN }}
107+
artifacts: "~/${{ github.event.repository.name }}.zip"

.zipignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git/*
2+
.github/*
3+
composer.*
4+
package.json
5+
update.json
6+
DOCKER_ENV
7+
docker_tag
8+
*.log

0 commit comments

Comments
 (0)