diff --git a/.github/workflows/sync-pr.yml b/.github/workflows/sync-pr.yml new file mode 100644 index 0000000..081a9c8 --- /dev/null +++ b/.github/workflows/sync-pr.yml @@ -0,0 +1,110 @@ +name: Sync and PR +permissions: + contents: write +on: + workflow_dispatch: + workflow_call: + schedule: + - cron: "20 4,8,12,16,20 * * *" + +jobs: + run: + runs-on: ubuntu-24.04 + name: PHP ${{ matrix.php-version }} + strategy: + matrix: + include: +# - php-version: '8.1' +# php-version-major: 8 +# php-version-minor: 1 +# - php-version: '8.2' +# php-version-major: 8 +# php-version-minor: 2 +# - php-version: '8.3' +# php-version-major: 8 +# php-version-minor: 3 + - php-version: '8.4' + php-version-major: 8 + php-version-minor: 4 + + steps: + - uses: actions/checkout@v4 + with: + path: builder + + - name: Clone PHP Documentation + uses: actions/checkout@v4 + with: + repository: PHPWatch/winget-pkgs + path: winget-pkgs + token: ${{ secrets.PKGS_TOKEN }} + sparse-checkout: | + manifests/p/PHP + + - name: Sync fork + run: | + cd winget-pkgs + git remote add upstream https://github.com/microsoft/winget-pkgs.git + git pull upstream master + git push origin master + cd ../ + + - name: Update version info + id: version_update + run: | + cd builder + php generate.php ${{ matrix.php-version }} + cat winget-commit-message.md + cat winget-pr-template.md + if [[ -f "NEW_VERSION" ]]; then + echo "new_version=$(cat NEW_VERSION)" >> $GITHUB_OUTPUT + else + echo "new_version=none" >> $GITHUB_OUTPUT + fi + + - name: "List dirs: generated" + run: find builder/manifests | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/" + + - name: "List dirs: Upstream" + run: find winget-pkgs/manifests/p/PHP/PHP | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/" + + - name: Generate commit message + id: commit_msg + if: ${{ steps.version_update.outputs.new_version }} != "none" + run: | + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "commit_msg<<$EOF" >> $GITHUB_OUTPUT + cat builder/winget-commit-message.md >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + echo "--New Version--" + echo ${{ steps.version_update.outputs.new_version }} + + - name: Remove old files from winget-pkgs + if: ${{ steps.version_update.outputs.new_version }} != "none" + run: | + rm -r winget-pkgs/manifests/p/PHP/PHP/${{ matrix.php-version-major }}/${{ matrix.php-version-minor }} + cp -r builder/manifests/p/PHP/PHP/${{ matrix.php-version-major }}/${{ matrix.php-version-minor }} winget-pkgs/manifests/p/PHP/PHP/${{ matrix.php-version-major }}/${{ matrix.php-version-minor }} + + - name: Commit data + uses: stefanzweifel/git-auto-commit-action@v5 + if: ${{ steps.version_update.outputs.new_version }} != "none" + with: + commit_message: ${{ steps.commit_msg.outputs.commit_msg }} + branch: main + add_options: '-A' + repository: builder + tagging_message: ${{ steps.commit_msg.outputs.commit_msg }} + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + if: ${{ steps.version_update.outputs.new_version }} != "none" + with: + token: ${{ secrets.PKGS_TOKEN }} + path: "winget-pkgs" + body-path: builder/winget-pr-template.md + add-paths: "manifests/p/PHP/PHP/${{ matrix.php-version-major }}/${{ matrix.php-version-minor }}" + commit-message: ${{ steps.commit_msg.outputs.commit_msg }} + title: "[PHP] Add new version ${{ matrix.php-version-major }}.${{ matrix.php-version-minor }}" + committer: "Ayesh Karunaratne " + author: "Ayesh Karunaratne " + branch: "php-version-${{ matrix.php-version-major }}-${{ matrix.php-version-minor }}" diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml deleted file mode 100644 index 8085c3a..0000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Sync PHP Package Versions -permissions: - contents: write -on: - workflow_dispatch: - workflow_call: - schedule: - - cron: "20 4,8,12,16,20 * * *" - -jobs: - run: - runs-on: ubuntu-24.04 - name: Update version info - steps: - - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@verbose - with: - php-version: '8.4' - - - name: "Update version info" - run: | - php generate.php 8.1 - php generate.php 8.2 - php generate.php 8.3 - php generate.php 8.4 - - - name: List dirs - run: find . | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/" - - - name: Generate commit message - id: commit_msg - run: echo "commit_msg=$(date +"%Y.%m.%d")" >> "$GITHUB_OUTPUT" - - - name: Commit data - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: Automatic updates - ${{ steps.commit_msg.outputs.commit_msg }} - branch: main - add_options: '-A' - tagging_message: ${{ steps.commit_msg.outputs.commit_msg }} diff --git a/.gitignore b/.gitignore index e69de29..9c62daf 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,3 @@ +/winget-commit-message.md +/winget-pr-template.md +/NEW_VERSION diff --git a/generate.php b/generate.php index f62edfa..03f0cd6 100644 --- a/generate.php +++ b/generate.php @@ -14,6 +14,8 @@ final class ManifestGenerator { private const string MATCH_DOWNLOAD_URL_X64 = '~Zip.*?sha256:\s(?[a-z\d]{64})~s'; private const string MATCH_DOWNLOAD_URL_X86 = '~Zip.*?sha256:\s(?[a-z\d]{64})~s'; + private ?string $newVersion = null; + public static function getHelp(): string { $help = []; $help[] = '== PHP Winget Manifest Builder =='; @@ -44,6 +46,21 @@ public function run(): void { $this->saveManifests($matches); } + public function showNewVersion(): void { + if ($this->newVersion) { + echo $this->newVersion; + } + } + + public function setNewVersionToEnv(): void { + if ($this->newVersion) { + putenv('PHP_NEW_VERSION=' . $this->version); + } + else { + putenv('PHP_NEW_VERSION=0'); + } + } + private function getAndParseInfo(): array { $return = [ 'version' => $this->version, @@ -98,11 +115,6 @@ private function getAndParseInfo(): array { private function saveManifests(array $data): void { $versionParts = explode('.', $data['version']); - $files = [ - 'PHP.PHP.(version).installer.yaml', - 'PHP.PHP.(version).locale.en-US.yaml', - 'PHP.PHP.(version).yaml', - ]; $replacements = [ '%version%' => $this->version, '%releasedate%' => $data['date'], @@ -120,12 +132,24 @@ private function saveManifests(array $data): void { $folder = self::BASE_PATH . '/manifests/p/PHP/PHP/%versionmajor%/%versionminor%/%fullversion%'; $folder = strtr($folder, $replacements); + $files = [ + 'PHP.PHP.(version).installer.yaml' => $folder . '/' . 'PHP.PHP.(version).installer.yaml', + 'PHP.PHP.(version).locale.en-US.yaml' => $folder . '/' . 'PHP.PHP.(version).locale.en-US.yaml', + 'PHP.PHP.(version).yaml' => $folder . '/' . 'PHP.PHP.(version).yaml', + 'winget-commit-message.md' => __DIR__ . '/winget-commit-message.md', + 'winget-pr-template.md' => __DIR__ . '/winget-pr-template.md', + ]; + + $isNewVersion = !is_dir($folder); + if ($isNewVersion) { + $this->newVersion = $data['fullversion']; + } + if (!is_dir($folder) && !mkdir($folder, recursive: true) && !is_dir($folder)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $folder)); } - foreach ($files as $fileName) { - $targetFile = $folder . '/' . $fileName; + foreach ($files as $fileName => $targetFile) { $fileContents = file_get_contents(self::BASE_PATH . '/templates/' . $fileName); $targetFile = strtr($targetFile, $replacements + ['(version)' => $this->version]); @@ -138,6 +162,15 @@ private function saveManifests(array $data): void { } } + public function saveNewVersionToFile(string $file): void { + if (file_exists($file)) { + unlink($file); + } + if ($this->newVersion) { + file_put_contents($file, $this->newVersion); + } + } + private function getDownloadUrlInfo(string $url): string { $ch = curl_init($url); curl_setopt_array($ch, [ @@ -181,6 +214,9 @@ private function getDownloadUrlInfo(string $url): string { try { $runner = new ManifestGenerator($ver); $runner->run(); + $runner->showNewVersion(); + $runner->setNewVersionToEnv(); + $runner->saveNewVersionToFile(__DIR__ . '/NEW_VERSION'); } catch (\Exception $exception) { echo $exception->getMessage(); diff --git a/templates/winget-commit-message.md b/templates/winget-commit-message.md new file mode 100644 index 0000000..f26872a --- /dev/null +++ b/templates/winget-commit-message.md @@ -0,0 +1,9 @@ +[PHP] Update `PHP.PHP.%versionmajor%.%versionminor%` to `%fullversion%` + +Release: https://php.watch/versions/%versionmajor%.%versionminor%/releases/%fullversion% +Tag: https://github.com/php/php-src/releases/tag/php-%fullversion% +Download x86: %url-x86% +Checksum x86: %hash-x86% +Download x64: %url-x64% +Checksum x64: %hash-x64% + diff --git a/templates/winget-pr-template.md b/templates/winget-pr-template.md new file mode 100644 index 0000000..5fbffe6 --- /dev/null +++ b/templates/winget-pr-template.md @@ -0,0 +1,20 @@ +Updates `PHP.PHP.%versionmajor%.%versionminor%` to PHP `%fullversion%` + +**PHP %fullversion%** +Download x86: %url-x86% +Checksum x86: %hash-x86% +Download x64: %url-x64% +Checksum x64: %hash-x64% + +Checklist for Pull Requests +- [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)? +- [ ] Is there a linked Issue? + +Manifests +- [x] Have you checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change? +- [x] This PR only modifies one (1) manifest +- [x] Have you [validated](https://github.com/microsoft/winget-pkgs/blob/master/doc/Authoring.md#validation) your manifest locally with `winget validate --manifest `? +- [x] Have you tested your manifest locally with `winget install --manifest `? +- [x] Does your manifest conform to the [1.9 schema](https://github.com/microsoft/winget-pkgs/tree/master/doc/manifest/schema/1.9.0)? + +---