Skip to content

Commit 0146862

Browse files
authored
Merge pull request #30 from hydephp/release/v0.2.0
HydeCLI v0.2.0
2 parents 15998c7 + 0053e91 commit 0146862

File tree

9 files changed

+260
-3
lines changed

9 files changed

+260
-3
lines changed

.github/workflows/create-release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This workflow allows for the creation of a new release through the GitHub UI.
2+
# This is done by creating a pull request to the protected stable release branch.
3+
# From there, the publish-release.yml workflow will take over and publish the release.
4+
5+
name: Create a new release PR
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
type:
11+
type: choice
12+
description: The SemVer level of the release
13+
options:
14+
- patch
15+
- minor
16+
- major
17+
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
22+
jobs:
23+
24+
prepare-release:
25+
runs-on: ubuntu-latest
26+
name: Prepare a new release
27+
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
32+
ref: stable
33+
34+
- name: Pull latest changes from master
35+
run: |
36+
git fetch origin master:master
37+
git reset --hard master
38+
39+
- name: Bump application version
40+
id: bump-version
41+
run: |
42+
php ./bin/bump-application-version.php ${{ github.event.inputs.type }}
43+
echo "version=$(php ./bin/get-release-version.php)" >> $GITHUB_OUTPUT
44+
echo "Version: v$(php ./bin/get-release-version.php)"
45+
46+
- name: Create pull request
47+
uses: peter-evans/create-pull-request@v5
48+
with:
49+
commit-message: "HydeCLI v${{ steps.bump-version.outputs.version }}"
50+
title: "HydeCLI v${{ steps.bump-version.outputs.version }}"
51+
branch: "release/v${{ steps.bump-version.outputs.version }}"
52+
delete-branch: true
53+
54+
body: |
55+
This pull request was automatically created by the [HydeCLI release workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
56+
57+
Please review and merge it to publish a new release, which will be created automatically upon merge.
58+
reviewers: caendesilva
59+
labels: release

.github/workflows/publish-release.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# This workflow will build the application and publish a new release.
2+
# It is triggered by pushes to the protected stable branch used for releases.
3+
# This process is triggered via the GitHub UI using the create-release.yml action.
4+
5+
name: Build and publish a new release
6+
7+
on:
8+
push:
9+
branches: [ "stable" ]
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
16+
sync:
17+
runs-on: ubuntu-latest
18+
name: Merge stable branch into master
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
24+
ref: master
25+
26+
- name: Merge stable branch into master
27+
run: |
28+
git fetch origin stable:stable
29+
git merge stable
30+
git push origin master
31+
32+
build:
33+
runs-on: ubuntu-latest
34+
name: Build standalone executable
35+
36+
steps:
37+
- uses: actions/checkout@v3
38+
39+
- name: Cache Composer packages
40+
id: composer-cache
41+
uses: actions/cache@v3
42+
with:
43+
path: vendor
44+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
45+
restore-keys: |
46+
${{ runner.os }}-php-
47+
48+
- name: Install dependencies
49+
run: composer install --no-interaction --no-progress --no-suggest --prefer-dist
50+
51+
- name: Get build version
52+
id: build-version
53+
run: |
54+
echo "version=$(php ./bin/get-release-version.php)" >> $GITHUB_OUTPUT
55+
echo "Version: v$(php ./bin/get-release-version.php)"
56+
php ./bin/get-release-version.php > version
57+
58+
- name: Build executable
59+
run: php hyde standalone:build --build-version-suffix="${{ steps.build-version.outputs.sha_short }}"
60+
61+
- name: Verify executable
62+
run: php builds/hyde
63+
64+
- name: Verify executable version
65+
run: php builds/hyde --version
66+
67+
- name: Calculate checksum
68+
run: |
69+
cd builds
70+
sha256sum hyde > checksum.txt
71+
echo "SHA256 checksum of the application binary: $(cat checksum.txt)"
72+
73+
- name: Upload executable
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: hyde
77+
path: builds/hyde
78+
79+
- name: Upload the checksum artifact
80+
uses: actions/upload-artifact@v3
81+
with:
82+
name: checksum
83+
path: builds/checksum.txt
84+
85+
release:
86+
needs: build
87+
runs-on: ubuntu-latest
88+
name: Publish release
89+
90+
permissions:
91+
contents: write
92+
93+
steps:
94+
- name: Download the application artifact
95+
uses: actions/download-artifact@v3
96+
with:
97+
name: hyde
98+
path: builds
99+
100+
- name: Download the checksum artifact
101+
uses: actions/download-artifact@v3
102+
with:
103+
name: checksum
104+
path: builds
105+
106+
- name: Get build version
107+
run: echo "version=$(php ./bin/get-release-version.php)" >> $GITHUB_ENV
108+
109+
- name: Prepare version information
110+
run: echo "CHECKSUM=$(cat builds/checksum.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV
111+
112+
- name: Print version information
113+
run: |
114+
echo "Version: v${{ env.VERSION }}"
115+
echo "Checksum: ${{ env.CHECKSUM }}"
116+
117+
- name: Create a release
118+
uses: ncipollo/release-action@v1
119+
with:
120+
name: v${{ env.VERSION }}
121+
tag: v${{ env.VERSION }}
122+
commit: ${{ github.sha }}
123+
updateOnlyUnreleased: true
124+
generateReleaseNotes: true
125+
artifacts: builds/hyde, builds/checksum.txt

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Test Suite
22

33
on:
44
push:
5-
branches: [ "master", "develop" ]
5+
branches: [ "master", "develop", "stable", "release/**" ]
66
pull_request:
7-
branches: [ "master", "develop" ]
7+
branches: [ "master", "develop", "stable", "release/**" ]
88

99
jobs:
1010
coverage-tests:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ This is an experimental standalone executable for the static site generator Hyde
1212

1313
With this global binary, you can use the HydePHP CLI to generate quality static sites faster than ever before!
1414

15+
### ⚠ Beta software notice
16+
17+
Please note that the standalone HydePHP version is **experimental**, and that there may be breaking changes and bugs until the 1.0 release.
18+
- In the meantime, you may want to use the standard HydePHP project: https://github.com/hydephp/hyde
19+
1520
## Installation
1621

1722
### Using Composer

app/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class Application extends \Hyde\Foundation\Application
88
{
9+
final public const APP_VERSION = '0.2.0';
10+
911
public function getCachedPackagesPath(): string
1012
{
1113
// Since we have a custom path for the cache directory, we need to return it here.

app/config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
|
3838
*/
3939

40-
'version' => Hyde\Hyde::version().' <fg=gray>-</> <comment>Experimental Standalone</comment>',
40+
'version' => sprintf("v%s <fg=gray>-</> <comment>Experimental Standalone</comment> <fg=gray>-</> <fg=gray>(HydePHP v%s)</>",
41+
\App\Application::APP_VERSION, \Hyde\Foundation\HydeKernel::VERSION
42+
),
4143

4244
/*
4345
|--------------------------------------------------------------------------

bin/bump-application-version.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* @interal Updates the version number in the app/Application.php file
5+
*
6+
* @usage php bin/bump-application-version.php [major|minor|patch]
7+
*/
8+
9+
echo "Bumping application version!\n";
10+
11+
// Get type from argument input
12+
$type = $argv[1] ?? 'patch';
13+
14+
// Get the Application class
15+
$application = file_get_contents(__DIR__.'/../app/Application.php');
16+
17+
// Get current version
18+
$version = trim(str_replace(['final public const APP_VERSION', '=', '\'', ';'], '', array_values(
19+
array_filter(explode("\n", $application), fn ($line) => str_contains($line, 'APP_VERSION'))
20+
)[0]));
21+
22+
echo "Current version: v$version\n";
23+
24+
// Split version into parts
25+
$parts = explode('.', $version);
26+
27+
// Get the index of the part to increment
28+
$index = match ($type) {
29+
'major' => 0,
30+
'minor' => 1,
31+
'patch' => 2,
32+
default => throw new Exception(sprintf('Invalid version type %s', $type))
33+
};
34+
35+
// Increment the part
36+
$parts[$index]++;
37+
38+
// Reset all parts after the incremented part
39+
for ($i = $index + 1; $i < count($parts); $i++) {
40+
$parts[$i] = 0;
41+
}
42+
43+
// Join the parts back together
44+
$version = implode('.', $parts);
45+
46+
echo "New version: v$version\n";
47+
48+
// Update the version in the Application class
49+
$application = preg_replace('/APP_VERSION = \'(.*)\'/', "APP_VERSION = '$version'", $application);
50+
file_put_contents(__DIR__.'/../app/Application.php', $application);

bin/get-release-version.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
/** @interal Gets the version number from the app/Application.php file */
4+
$application = file_get_contents(__DIR__.'/../app/Application.php');
5+
6+
echo trim(str_replace(['final public const APP_VERSION', '=', '\'', ';'], '', array_values(
7+
array_filter(explode("\n", $application), fn ($line) => str_contains($line, 'APP_VERSION'))
8+
)[0]));

tests/Unit/ApplicationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
use App\Application;
44
use Hyde\Foundation\Application as HydeApplication;
55

6+
test('application version constant follows semantic versioning', function () {
7+
$version = Application::APP_VERSION;
8+
9+
expect($version)->toMatch('/^\d+\.\d+\.\d+$/');
10+
});
11+
612
test('custom application extends Hyde application', function () {
713
expect(new Application())->toBeInstanceOf(HydeApplication::class);
814
});

0 commit comments

Comments
 (0)