-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'minor-next' into bootstrap-exit-warnings
- Loading branch information
Showing
1,589 changed files
with
65,210 additions
and
25,682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine; | ||
|
||
use pocketmine\utils\Internet; | ||
use function dirname; | ||
use function fwrite; | ||
use function is_array; | ||
use function json_decode; | ||
use function json_encode; | ||
use const JSON_THROW_ON_ERROR; | ||
use const STDERR; | ||
|
||
require dirname(__DIR__, 2) . '/vendor/autoload.php'; | ||
|
||
/** | ||
* @phpstan-return array<string, mixed> | ||
*/ | ||
function generateDiscordEmbed(string $version, string $channel, string $description, string $detailsUrl, string $sourceUrl, string $pharDownloadUrl, string $buildLogUrl, int $newsPingRoleId, ?string $phpDownloadUrl) : array{ | ||
if($phpDownloadUrl !== null){ | ||
$phpEmbedLink = " | [PHP Binaries]($phpDownloadUrl)"; | ||
}else{ | ||
$phpEmbedLink = ""; | ||
} | ||
return [ | ||
"content" => "<@&$newsPingRoleId> New PocketMine-MP release: $version ($channel)", | ||
"embeds" => [ | ||
[ | ||
"title" => "New PocketMine-MP release: $version ($channel)", | ||
"description" => <<<DESCRIPTION | ||
$description | ||
[Details]($detailsUrl) | [Source Code]($sourceUrl) | [Build Log]($buildLogUrl) | [Download]($pharDownloadUrl)$phpEmbedLink | ||
DESCRIPTION, | ||
"url" => $detailsUrl, | ||
"color" => $channel === "stable" ? 0x57ab5a : 0xc69026 | ||
] | ||
] | ||
]; | ||
} | ||
|
||
if(count($argv) !== 6){ | ||
fwrite(STDERR, "Required arguments: github repo, version, API token, webhook URL, ping role ID\n"); | ||
exit(1); | ||
} | ||
[, $repo, $tagName, $token, $hookURL, $newsPingRoleId] = $argv; | ||
|
||
$result = Internet::getURL('https://api.github.com/repos/' . $repo . '/releases/tags/' . $tagName, extraHeaders: [ | ||
'Authorization: token ' . $token | ||
]); | ||
if($result === null){ | ||
fwrite(STDERR, "failed to access GitHub API\n"); | ||
return; | ||
} | ||
if($result->getCode() !== 200){ | ||
fwrite(STDERR, "Error accessing GitHub API: " . $result->getCode() . "\n"); | ||
fwrite(STDERR, $result->getBody() . "\n"); | ||
exit(1); | ||
} | ||
|
||
$releaseInfoJson = json_decode($result->getBody(), true, JSON_THROW_ON_ERROR); | ||
if(!is_array($releaseInfoJson)){ | ||
fwrite(STDERR, "Invalid release JSON returned from GitHub API\n"); | ||
exit(1); | ||
} | ||
$buildInfoPath = 'https://github.com/' . $repo . '/releases/download/' . $tagName . '/build_info.json'; | ||
|
||
$buildInfoResult = Internet::getURL($buildInfoPath, extraHeaders: [ | ||
'Authorization: token ' . $token | ||
]); | ||
if($buildInfoResult === null){ | ||
fwrite(STDERR, "missing build_info.json\n"); | ||
exit(1); | ||
} | ||
if($buildInfoResult->getCode() !== 200){ | ||
fwrite(STDERR, "error accessing build_info.json: " . $buildInfoResult->getCode() . "\n"); | ||
fwrite(STDERR, $buildInfoResult->getBody() . "\n"); | ||
exit(1); | ||
} | ||
|
||
$buildInfoJson = json_decode($buildInfoResult->getBody(), true, JSON_THROW_ON_ERROR); | ||
if(!is_array($buildInfoJson)){ | ||
fwrite(STDERR, "invalid build_info.json\n"); | ||
exit(1); | ||
} | ||
$detailsUrl = $buildInfoJson["details_url"]; | ||
$sourceUrl = $buildInfoJson["source_url"]; | ||
$pharDownloadUrl = $buildInfoJson["download_url"]; | ||
$buildLogUrl = $buildInfoJson["build_log_url"]; | ||
$phpBinaryUrl = $buildInfoJson["php_download_url"] ?? null; | ||
|
||
$description = $releaseInfoJson["body"]; | ||
|
||
$discordPayload = generateDiscordEmbed( | ||
$buildInfoJson["base_version"], | ||
$buildInfoJson["channel"], | ||
$description, | ||
$detailsUrl, | ||
$sourceUrl, | ||
$pharDownloadUrl, | ||
$buildLogUrl, | ||
(int) $newsPingRoleId, | ||
$phpBinaryUrl | ||
); | ||
|
||
$response = Internet::postURL( | ||
$hookURL, | ||
json_encode($discordPayload, JSON_THROW_ON_ERROR), | ||
extraHeaders: ['Content-Type: application/json'] | ||
); | ||
if($response?->getCode() !== 204){ | ||
fwrite(STDERR, "failed to send Discord webhook\n"); | ||
fwrite(STDERR, $response?->getBody() ?? "no response body\n"); | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Notify Discord webhook of release | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP and tools | ||
uses: shivammathur/setup-php@2.31.1 | ||
with: | ||
php-version: 8.2 | ||
|
||
- name: Restore Composer package cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cache/composer/files | ||
~/.cache/composer/vcs | ||
key: "composer-v2-cache-${{ hashFiles('./composer.lock') }}" | ||
restore-keys: | | ||
composer-v2-cache- | ||
- name: Install Composer dependencies | ||
run: composer install --no-dev --prefer-dist --no-interaction --ignore-platform-reqs | ||
|
||
- name: Get actual tag name | ||
id: tag-name | ||
run: echo TAG_NAME=$(echo "${{ github.ref }}" | sed 's{^refs/tags/{{') >> $GITHUB_OUTPUT | ||
|
||
- name: Run webhook post script | ||
run: php .github/workflows/discord-release-embed.php ${{ github.repository }} ${{ steps.tag-name.outputs.TAG_NAME }} ${{ github.token }} ${{ secrets.DISCORD_RELEASE_WEBHOOK }} ${{ secrets.DISCORD_NEWS_PING_ROLE_ID }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Draft release from PR | ||
|
||
on: | ||
#presume that pull_request_target is safe at this point, since the PR was approved and merged | ||
#we need write access to prepare the release & create comments | ||
pull_request_target: | ||
types: | ||
- closed | ||
branches: | ||
- stable | ||
- minor-next | ||
- major-next | ||
- "legacy/*" | ||
paths: | ||
- "src/VersionInfo.php" | ||
|
||
jobs: | ||
check: | ||
name: Check release | ||
uses: ./.github/workflows/draft-release-pr-check.yml | ||
|
||
draft: | ||
name: Create GitHub draft release | ||
needs: [check] | ||
if: needs.check.outputs.valid == 'true' | ||
|
||
uses: ./.github/workflows/draft-release.yml | ||
|
||
post-draft-url-comment: | ||
name: Post draft release URL as comment | ||
needs: [draft] | ||
|
||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Post draft release URL on PR | ||
uses: thollander/actions-comment-pull-request@v3 | ||
with: | ||
message: "[Draft release ${{ needs.draft.outputs.version }}](${{ needs.draft.outputs.draft-url }}) has been created for commit ${{ github.sha }}. Please review and publish it." | ||
|
||
trigger-post-release-workflow: | ||
name: Trigger post-release RestrictedActions workflow | ||
# Not sure if needs is actually needed here | ||
needs: [check] | ||
if: needs.check.outputs.valid == 'true' | ||
|
||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Generate access token | ||
id: generate-token | ||
uses: actions/create-github-app-token@v1 | ||
with: | ||
app-id: ${{ vars.RESTRICTED_ACTIONS_DISPATCH_ID }} | ||
private-key: ${{ secrets.RESTRICTED_ACTIONS_DISPATCH_KEY }} | ||
owner: ${{ github.repository_owner }} | ||
repositories: RestrictedActions | ||
|
||
- name: Dispatch post-release restricted action | ||
uses: peter-evans/repository-dispatch@v3 | ||
with: | ||
token: ${{ steps.generate-token.outputs.token }} | ||
repository: ${{ github.repository_owner }}/RestrictedActions | ||
event-type: pocketmine_mp_post_release | ||
client-payload: '{"branch": "${{ github.ref }}"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#Allows creating a release by pushing a tag | ||
#This might be useful for retroactive releases | ||
name: Draft release from git tag | ||
|
||
on: | ||
push: | ||
tags: "*" | ||
|
||
jobs: | ||
draft: | ||
name: Create GitHub draft release | ||
if: "startsWith(github.event.head_commit.message, 'Release ')" | ||
uses: ./.github/workflows/draft-release.yml |
Oops, something went wrong.