Skip to content

Commit 55461a0

Browse files
authored
Merge pull request #3 from packagist/push-slkqvukxxwtk
Configure Trusted Publishing
2 parents dec714b + af25b15 commit 55461a0

File tree

4 files changed

+281
-31
lines changed

4 files changed

+281
-31
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# Create your artifact file here
2626

2727
- name: "Publish artifact"
28-
uses: packagist/publish-artifact-github-action
28+
uses: packagist/artifact-publish-github-action
2929
with:
3030
package_name: 'acme/package'
3131
organization_url_name: 'acme-org'
@@ -44,7 +44,7 @@ The `package_name` input parameter allows you to configure the name of the packa
4444
For example:
4545

4646
```yaml
47-
- uses: packagist/publish-artifact-github-action
47+
- uses: packagist/artifact-publish-github-action
4848
with:
4949
package_name: "acme/package"
5050
```
@@ -56,7 +56,7 @@ The `organization_url_name` input parameter allows you to configure the Private
5656
For example:
5757

5858
```yaml
59-
- uses: packagist/publish-artifact-github-action
59+
- uses: packagist/artifact-publish-github-action
6060
with:
6161
organization_url_name: "acme/org"
6262
```
@@ -68,7 +68,7 @@ The `artifact` input parameter allows you to configure which artifact you would
6868
For example:
6969

7070
```yaml
71-
- uses: packagist/publish-artifact-github-action
71+
- uses: packagist/artifact-publish-github-action
7272
with:
7373
artifact: '/full/path/to/artifact.zip'
7474
```
@@ -80,7 +80,7 @@ The `private_packagist_url` input parameter allows you to configure the URL of y
8080
For example:
8181

8282
```yaml
83-
- uses: packagist/publish-artifact-github-action
83+
- uses: packagist/artifact-publish-github-action
8484
with:
8585
private_packagist_url: 'https://private-packagist-self-hosted.example'
8686
```

bin/publish.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
22

3+
use Http\Client\Common\Plugin\LoggerPlugin;
4+
use Monolog\Handler\StreamHandler;
5+
use Monolog\Logger;
36
use PrivatePackagist\ApiClient\Client;
47
use PrivatePackagist\ApiClient\Exception\HttpTransportException;
58
use PrivatePackagist\ApiClient\Exception\ResourceNotFoundException;
9+
use PrivatePackagist\ApiClient\HttpClient\HttpPluginClientBuilder;
610
use Symfony\Component\Mime\MimeTypes;
711

812
require_once __DIR__ . '/../vendor/autoload.php';
@@ -12,23 +16,30 @@
1216
}
1317

1418
$packageName = $argv[1];
15-
$fileName = $argv[2];
19+
$fileNameWithPath = $argv[2];
1620
$organizationUrlName = $argv[3];
1721
$privatePackagistUrl = $argv[4];
22+
$fileName = basename($fileNameWithPath);
1823

19-
if (!file_exists($fileName)) {
20-
throw new \RuntimeException('File not found: ' . $fileName);
24+
if (!file_exists($fileNameWithPath)) {
25+
throw new \RuntimeException('File not found: ' . $fileNameWithPath);
2126
}
2227

23-
$client = new Client(null, $privatePackagistUrl);
28+
$logger = new Logger('trusted-publishing');
29+
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
30+
$httpClientBuilder = new HttpPluginClientBuilder();
31+
$httpClientBuilder->addPlugin(new LoggerPlugin($logger));
32+
$client = new Client(null, $privatePackagistUrl, null, $logger);
2433

2534
if (isset($_SERVER['PRIVATE_PACKAGIST_API_KEY']) && isset($_SERVER['PRIVATE_PACKAGIST_API_SECRET'])) {
2635
$client->authenticate($_SERVER['PRIVATE_PACKAGIST_API_KEY'], $_SERVER['PRIVATE_PACKAGIST_API_SECRET']);
36+
} else {
37+
$client->authenticateWithTrustedPublishing($organizationUrlName, $packageName);
2738
}
2839

2940
try {
30-
$file = file_get_contents($fileName);
31-
$contentType = MimeTypes::getDefault()->guessMimeType($fileName);
41+
$file = file_get_contents($fileNameWithPath);
42+
$contentType = MimeTypes::getDefault()->guessMimeType($fileNameWithPath);
3243

3344
try {
3445
$client->packages()->artifacts()->add($packageName, $file, $contentType, $fileName);

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"require": {
3-
"private-packagist/api-client": "^1.38",
3+
"private-packagist/api-client": "^1.39.0",
4+
"private-packagist/oidc-identities": "^1.0.1",
45
"nyholm/psr7": "^1.8",
56
"symfony/http-client": "^5.4",
6-
"symfony/mime": "^5.4"
7+
"symfony/mime": "^5.4",
8+
"monolog/monolog": "^2.10",
9+
"php-http/logger-plugin": "^1.3"
710
},
811
"config": {
912
"allow-plugins": {

0 commit comments

Comments
 (0)