This query retrieves the latest artifacts from the GitHub Actions API, and extracts their URL to be downloaded, avoiding the need for the client to be signed in to GitHub (eg: using the wp plugin install
WP-CLI command to install the latest version of your plugin under development).
query RetrieveGitHubAccessToken {
githubAccessToken : _env ( name : "GITHUB_ACCESS_TOKEN" )
@export ( as : "githubAccessToken" )
@remove
}
query RetrieveProxyArtifactDownloadURLs (
$repoAccount : String!
$repoProject : String!
$numberArtifacts : Int! = 1
)
@depends ( on : "RetrieveGitHubAccessToken" )
{
githubArtifactsEndpoint : _sprintf (
string : "https://api.github.com/repos/%s/%s/actions/artifacts?per_page=%s" ,
values : [ $repoAccount , $repoProject , $numberArtifacts ]
)
@remove
# Retrieve Artifact data from GitHub Actions API
gitHubArtifactData : _sendJSONObjectItemHTTPRequest (
input : {
url : $__githubArtifactsEndpoint ,
options : {
auth : {
password : $githubAccessToken
},
headers : [
{
name : "Accept" ,
value : "application/vnd.github+json"
}
]
}
}
)
@remove
# Extract the URL from within each "artifacts" item
gitHubProxyArtifactDownloadURLs : _objectProperty (
object : $__gitHubArtifactData ,
by : {
key : "artifacts"
}
)
@underEachArrayItem ( passValueOnwardsAs : "artifactItem" )
@applyField (
name : "_objectProperty" ,
arguments : {
object : $artifactItem ,
by : {
key : "archive_download_url"
}
},
setResultInResponse : true
)
@export ( as : "gitHubProxyArtifactDownloadURLs" )
}
query CreateHTTPRequestInputs
@depends ( on : "RetrieveProxyArtifactDownloadURLs" )
{
httpRequestInputs : _echo ( value : $gitHubProxyArtifactDownloadURLs )
@underEachArrayItem (
passValueOnwardsAs : "url"
)
@applyField (
name : "_objectAddEntry" ,
arguments : {
object : {
options : {
auth : {
password : $githubAccessToken
},
headers : {
name : "Accept" ,
value : "application/vnd.github+json"
},
allowRedirects : null
}
},
key : "url" ,
value : $url
},
setResultInResponse : true
)
@export ( as : "httpRequestInputs" )
@remove
}
query RetrieveActualArtifactDownloadURLs
@depends ( on : "CreateHTTPRequestInputs" )
{
_sendHTTPRequests (
inputs : $httpRequestInputs
) {
artifactDownloadURL : header ( name : "Location" )
@export ( as : "artifactDownloadURLs" , type : LIST )
}
}
query RetrieveLatestArtifactDownloadURLsFromGitHub
@depends ( on : "RetrieveActualArtifactDownloadURLs" )
{
artifactDownloadURLs : _echo ( value : $artifactDownloadURLs )
}
Copy
And define in wp-config.php
:
define ( 'GITHUB_ACCESS_TOKEN' , '{ your github access token }' );
Copy