Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type (auto = detect from conventional commits)'
required: true
type: choice
default: auto
options:
- auto
- patch
- minor
- major
repo:
description: 'Upstream repository to release (empty = all)'
required: false
type: choice
default: ''
options:
- ''
- core
- contrib
filter:
description: 'Filter downstream repositories by prefix'
required: false
type: string
default: ''

jobs:
release:
name: Create releases
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: json, simplexml
coverage: none

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
ARGS="--non-interactive"
if [ "${{ inputs.version_bump }}" != "auto" ]; then
ARGS="$ARGS --version-bump=${{ inputs.version_bump }}"
fi
if [ -n "${{ inputs.repo }}" ]; then
ARGS="$ARGS --repo=${{ inputs.repo }}"
fi
if [ -n "${{ inputs.filter }}" ]; then
ARGS="$ARGS --filter=${{ inputs.filter }}"
fi
bin/otel release:run $ARGS
2 changes: 2 additions & 0 deletions src/Console/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenTelemetry\DevTools\Console\Command\Packages\ValidateInstallationCommand;
use OpenTelemetry\DevTools\Console\Command\Packages\ValidatePackagesCommand;
use OpenTelemetry\DevTools\Console\Command\Release\PeclCommand;
use OpenTelemetry\DevTools\Console\Command\Release\PeclPrCommand;
use OpenTelemetry\DevTools\Console\Command\Release\PeclTagCommand;
use OpenTelemetry\DevTools\Console\Command\Release\ReleaseCommand;
use OpenTelemetry\DevTools\Console\Command\Release\ReleaseListCommand;
Expand Down Expand Up @@ -41,6 +42,7 @@ private function initCommands(): void
new ReleaseCommand(),
new ReleaseListCommand(),
new PeclCommand(),
new PeclPrCommand(),
new PeclTagCommand(),
]);
}
Expand Down
9 changes: 9 additions & 0 deletions src/Console/Command/Release/AbstractReleaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ protected function post(string $url, string $body): ResponseInterface
return $this->client->sendRequest($request);
}

protected function put(string $url, string $body): ResponseInterface
{
$request = new Request('PUT', $url, $this->headers(), $body);
$this->output->isVerbose() && $this->output->writeln("[HTTP] PUT {$url}");
$this->output->isVeryVerbose() && $this->output->writeln("[HTTP body] {$body}");

return $this->client->sendRequest($request);
}

protected function get_latest_release(Repository $repository): ?Release
{
$release_url = "https://api.github.com/repos/{$repository->downstream}/releases/latest";
Expand Down
67 changes: 56 additions & 11 deletions src/Console/Command/Release/PeclCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ protected function configure(): void
->setName('release:pecl')
->setDescription('Update auto-instrumentation package.xml for PECL release')
->addOption('force', ['f'], InputOption::VALUE_NONE, 'force')
->addOption('version', null, InputOption::VALUE_OPTIONAL, 'new version (skips prompt)')
->addOption('stability', null, InputOption::VALUE_OPTIONAL, 'release stability: stable|beta (skips prompt)', null)
->addOption('output-file', null, InputOption::VALUE_OPTIONAL, 'write updated package.xml to this file path instead of stdout')
->addOption('update-header', null, InputOption::VALUE_OPTIONAL, 'path to local php_opentelemetry.h to update PHP_OPENTELEMETRY_VERSION')
;
}

Expand Down Expand Up @@ -80,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* @psalm-suppress PossiblyNullPropertyFetch
*/
private function process(Repository $repository, SimpleXMLElement $xml): void
protected function process(Repository $repository, SimpleXMLElement $xml): void
{
$cnt = count($repository->commits);
$this->output->writeln("<info>Last release {$repository->latestRelease->version} @ {$repository->latestRelease->timestamp}</info>");
Expand All @@ -91,22 +95,28 @@ private function process(Repository $repository, SimpleXMLElement $xml): void
$prev = ($repository->latestRelease === null)
? '-nothing-'
: $repository->latestRelease->version;
$question = new Question("<question>Latest={$prev}, enter new tag (blank to skip):</question>", null);

$helper = new QuestionHelper();
$newVersion = $helper->ask($this->input, $this->output, $question);
$newVersion = $this->input->getOption('version');
if (!$newVersion) {
$question = new Question("<question>Latest={$prev}, enter new tag (blank to skip):</question>", null);
$newVersion = $helper->ask($this->input, $this->output, $question);
}
if (!$newVersion) {
$this->output->writeln("<info>[SKIP] not going to release {$repository->downstream}</info>");

return;
}

$question = new ChoiceQuestion(
'<question>Is this a beta or stable release?</question>',
['stable', 'beta'],
'stable',
);
$stability = $helper->ask($this->input, $this->output, $question);
$stability = $this->input->getOption('stability');
if (!$stability) {
$question = new ChoiceQuestion(
'<question>Is this a beta or stable release?</question>',
['stable', 'beta'],
'stable',
);
$stability = $helper->ask($this->input, $this->output, $question);
}

//new release data
$release = [
Expand All @@ -122,7 +132,20 @@ private function process(Repository $repository, SimpleXMLElement $xml): void
],
'notes' => $this->format_notes($newVersion),
];
$this->output->writeln($this->convertPackageXml($xml, $release));
$xmlContent = $this->convertPackageXml($xml, $release);

$outputFile = $this->input->getOption('output-file');
if ($outputFile) {
file_put_contents($outputFile, $xmlContent);
$this->output->writeln("<info>[WRITTEN] package.xml -> {$outputFile}</info>");
} else {
$this->output->writeln($xmlContent);
}

$headerFile = $this->input->getOption('update-header');
if ($headerFile) {
$this->update_header_file($headerFile, $newVersion);
}
}

protected function convertPackageXml(SimpleXMLElement $xml, array $new): string
Expand Down Expand Up @@ -158,7 +181,29 @@ protected function convertPackageXml(SimpleXMLElement $xml, array $new): string
return $pretty->saveXML();
}

private function format_notes(string $version): string
private function update_header_file(string $path, string $version): void
{
if (!file_exists($path)) {
$this->output->writeln("<error>[ERROR] Header file not found: {$path}</error>");

return;
}
$contents = file_get_contents($path);
$updated = preg_replace(
'/(#define PHP_OPENTELEMETRY_VERSION ")[^"]+(")/m',
'${1}' . $version . '${2}',
$contents,
);
if ($updated === $contents) {
$this->output->writeln('<comment>[WARN] PHP_OPENTELEMETRY_VERSION define not found in header file</comment>');

return;
}
file_put_contents($path, $updated);
$this->output->writeln("<info>[UPDATED] PHP_OPENTELEMETRY_VERSION -> {$version} in {$path}</info>");
}

protected function format_notes(string $version): string
{
return sprintf('See https://github.com/%s/%s/releases/tag/%s', self::OWNER, self::REPO, $version);
}
Expand Down
Loading
Loading