Skip to content

Commit e7d71a1

Browse files
committed
fix CI/CD: Fixed path builds for build, tar and extract the builds in Release flow
1 parent a6ecb01 commit e7d71a1

File tree

5 files changed

+82
-29
lines changed

5 files changed

+82
-29
lines changed

.github/workflows/release.yml

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
php --version
5252
php githooks app:pre-build php
5353
php githooks app:build
54+
git status --short
5455
5556
- name: Upload build artifact
5657
uses: actions/upload-artifact@v4
@@ -113,32 +114,57 @@ jobs:
113114
name: Commit the Build
114115
needs: test_rc
115116
runs-on: ubuntu-latest
117+
strategy:
118+
matrix:
119+
operating-system: [ubuntu-latest]
120+
php-versions: ['7.1']
116121
permissions:
117122
contents: write
118123
steps:
119124
- name: Checkout
120125
uses: actions/checkout@v4
121126

127+
- name: Install PHP
128+
uses: shivammathur/setup-php@v2
129+
with:
130+
php-version: ${{ matrix.php-versions }}
131+
coverage: none
132+
133+
- name: Get composer cache directory
134+
id: composer-cache
135+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
136+
137+
- name: Cache dependencies
138+
uses: actions/cache@v4
139+
with:
140+
path: ${{ steps.composer-cache.outputs.dir }}
141+
key: ${{ runner.os }}-rc-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
142+
restore-keys: |
143+
${{ runner.os }}-
144+
145+
- name: Install dependencies
146+
run: |
147+
chmod -R +x tools/*
148+
tools/composer install --prefer-dist --no-progress
149+
122150
- name: Delete Old Builds
123151
run: rm builds/githooks builds/php7.1/githooks builds/php7.3/githooks
124152

125153
- uses: actions/download-artifact@v4
126154
with:
127-
name: githooks-71
128-
129-
- uses: actions/download-artifact@v4
130-
with:
131-
name: githooks-73
155+
path: ${{ github.GITHUB_WORKSPACE }}
132156

133-
- uses: actions/download-artifact@v4
134-
with:
135-
name: githooks-81
157+
- name: Display structure of downloaded files
158+
run: |
159+
ls -R | grep githooks
160+
ls
136161
137162
- name: Extract and check builds
138163
run: |
139-
tar -xvf githooks-71.tar
140-
tar -xvf githooks-73.tar
141-
tar -xvf githooks-81.tar
164+
php githooks app:extract-build --all
165+
# tar -xvf githooks-7.1/githooks-7.1.tar
166+
# tar -xvf githooks-7.3/githooks-7.3.tar
167+
# tar -xvf githooks-8.1/githooks-8.1.tar
142168
ls -lah builds
143169
git status
144170

app/Commands/ExtractBuildCommand.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class ExtractBuildCommand extends Command
1212
{
13-
protected $signature = 'app:extract-build';
13+
protected $signature = 'app:extract-build {--all}';
1414
protected $description = 'Extracts the build from the tar file after the build process.';
1515

1616
/** @var \Wtyd\GitHooks\Build\Build */
@@ -25,20 +25,40 @@ public function handle()
2525
{
2626
$this->title('Extract build');
2727

28-
$this->task(
29-
' <fg=yellow>1. Extracting build</>',
30-
$this->extractBuild()
31-
);
28+
$allBuilds = boolval($this->option('all'));
3229

33-
$this->task(
34-
' <fg=yellow>2. Check build</>',
35-
$this->checkBuild()
36-
);
30+
if ($allBuilds) {
31+
$this->task(
32+
' <fg=yellow>1. Extracting all builds</>',
33+
function () {
34+
$builds = Build::ALL_BUILDS;
35+
foreach ($builds as $tarFile) {
36+
$this->extractBuild($tarFile);
37+
}
38+
}
39+
);
40+
} else {
41+
$this->task(
42+
' <fg=yellow>1. Extracting build</>',
43+
$this->extractBuild()
44+
);
45+
46+
$this->task(
47+
' <fg=yellow>2. Check build</>',
48+
$this->checkBuild()
49+
);
50+
}
3751
}
3852

39-
private function extractBuild(): void
53+
/**
54+
* Files are in directory with him name. For example ./githooks-7.1/githooks-7.1.tar
55+
*
56+
* @param string $tarName For example: 'githooks-7.1.tar'
57+
*/
58+
private function extractBuild($tarName = null): void
4059
{
41-
$zipFile = File::name($this->build->getTarName()) . DIRECTORY_SEPARATOR . $this->build->getTarName();
60+
$tarName = $tarName ?? $this->build->getTarName();
61+
$zipFile = File::name($tarName) . DIRECTORY_SEPARATOR . $tarName;
4262
$zip = new PharData($zipFile);
4363
$resultado = $zip->extractTo('./', null, true); // extract to $this->build->getBuildPath();
4464
if (true === $resultado) {

app/Commands/Zero/BuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function build(string $name): BuildCommand
103103
// $this->tarBuild($name);
104104
// TODO la compilación bien pero falta mencionar el tar
105105
$this->output->writeln(
106-
sprintf(' Compiled successfully: <fg=green>%s</>', $this->build->getBuildPath() . DIRECTORY_SEPARATOR . $name)
106+
sprintf(' Compiled successfully: <fg=green>%s</>', $this->build->getBuildPath() . $name)
107107
);
108108

109109
return $this;

src/Build/Build.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
class Build
1010
{
11+
const ALL_BUILDS = ['githooks-7.1.tar', 'githooks-7.3.tar', 'githooks-8.1.tar'];
12+
1113
/** @var string */
1214
private $phpVersion;
1315

@@ -25,7 +27,7 @@ public function __construct()
2527
*/
2628
private function setPhpVersion(): void
2729
{
28-
$this->phpVersion = implode('.', array_slice(explode('.', phpversion()), 0, 2));
30+
$this->phpVersion = phpversion();
2931
}
3032

3133
/**
@@ -38,7 +40,7 @@ private function setPhpVersion(): void
3840
private function setBuildPath(): void
3941
{
4042
$path = 'builds' . DIRECTORY_SEPARATOR;
41-
43+
// TODO: Refactor this to use a switch statement like getTarName()
4244
if (version_compare($this->phpVersion, '7.1', '<')) {
4345
throw new Exception('GitHooks only supports php 7.1 or greater.', 1);
4446
}
@@ -56,6 +58,11 @@ public function getBuildPath(): string
5658
return $this->buildPath;
5759
}
5860

61+
public function getBinary(): string
62+
{
63+
return $this->buildPath . 'githooks';
64+
}
65+
5966
public function getPhpVersion(): string
6067
{
6168
return $this->phpVersion;
@@ -67,7 +74,7 @@ public function getPhpVersion(): string
6774
public function getTarName(): string
6875
{
6976
$tarName = '';
70-
switch ($this->phpVersion) {
77+
switch (implode('.', array_slice(explode('.', $this->phpVersion), 0, 2))) {
7178
case '7.1':
7279
case '7.2':
7380
$tarName = 'githooks-7.1.tar';

src/Utils/ComposerUpdater.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public static function phpOldVersions(): void
1717
return;
1818
}
1919

20-
$rootPaht = getcwd();
20+
$rootPath = getcwd();
2121
$build = new Build();
22-
$origin = str_replace('/', DIRECTORY_SEPARATOR, "$rootPaht/vendor/wtyd/githooks") . $build->getBuildPath() . DIRECTORY_SEPARATOR . 'githooks';
23-
$destiny = str_replace('/', DIRECTORY_SEPARATOR, "$rootPaht/vendor/bin/githooks");
22+
$origin = str_replace('/', DIRECTORY_SEPARATOR, "$rootPath/vendor/wtyd/githooks/") . $build->getBinary();
23+
$destiny = str_replace('/', DIRECTORY_SEPARATOR, "$rootPath/vendor/bin/githooks");
2424
if (file_exists($destiny)) {
2525
unlink($destiny);
2626
}

0 commit comments

Comments
 (0)