Skip to content

Commit

Permalink
Merge pull request #257 from xwp/fix/travis-docker
Browse files Browse the repository at this point in the history
Document NewRelic markers
  • Loading branch information
kasparsd authored Nov 9, 2023
2 parents 57f6432 + 7529e05 commit 2b31114
Show file tree
Hide file tree
Showing 8 changed files with 33,137 additions and 4,070 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": [ "plugin:@wordpress/eslint-plugin/recommended-with-formatting" ]
}
6 changes: 6 additions & 0 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ jobs:
- name: Deploy to production
if: github.ref_name == 'master'
run: npm run deploy-production

- name: Set NewRelic deploy marker
env:
NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }}
if: ${{ env.NEW_RELIC_API_KEY != null && github.ref_name == 'master' }}
run: npm run newrelic-mark-deploy -- --search "*-production" --api_key "${{ secrets.NEW_RELIC_API_KEY }}" --commit "${{ github.sha }}" --user "${{ github.actor }}" --description "$(git log -1 --pretty=%B)"
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"lint": [
"phpcs"
],
"format": [
"phpcbf"
],
"verify": [
"composer validate --no-check-all --no-check-publish --strict"
],
Expand Down
62 changes: 34 additions & 28 deletions local/scripts/new-relic-deployment-markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ if ( ! apiKey ) {

const searchQuery = {
query: `{
actor {
entitySearch(queryBuilder: {name: "*${ search }*"}) {
count
query
results {
entities {
name
guid
}
}
}
}
}`,
actor {
entitySearch( queryBuilder: { name: ${ JSON.stringify( search ) } } ) {
count
query
results {
entities {
name
guid
}
}
}
}
}`,
variables: '',
};

Expand All @@ -94,25 +94,31 @@ const searchRequest = https.request( 'https://api.newrelic.com/graphql', searchR
searchResponse.on( 'end', () => {
const guids = JSON.parse( responseBody ).data.actor.entitySearch.results.entities.map( ( entity ) => entity.guid );

// description is a commit message and can contain double quotes, new lines, which will break the GraphQL query.
description = description.replace( /"/g, '\\"' ).replace( /\n/g, '\\n' );

guids.forEach( ( guid ) => {
const timestamp = Date.now() + (120 * 1000); // Add two minutes to current timestamp to acocunt for difference between actual deployment from VIP.
const timestamp = Date.now() + ( 120 * 1000 ); // Add two minutes to current timestamp to acocunt for difference between actual deployment from VIP.

const deploymentMarkerQuery = {
query: `mutation {
changeTrackingCreateDeployment(deployment: {version: "${ commit }", entityGuid: "${ guid }", timestamp: ${ timestamp }, commit: "${ commit }", user: "${ user }", description: "${ description }"}) {
changelog
commit
deepLink
deploymentId
deploymentType
description
groupId
user
}
}`,
changeTrackingCreateDeployment(
deployment: {
version: ${ JSON.stringify( commit ) },
entityGuid: ${ JSON.stringify( guid ) },
timestamp: ${ timestamp },
commit: ${ JSON.stringify( commit ) },
user: ${ JSON.stringify( user ) },
description: ${ JSON.stringify( description ) }
}
) {
changelog
commit
deepLink
deploymentId
deploymentType
description
groupId
user
}
}`,
variables: '',
};

Expand Down
Loading

0 comments on commit 2b31114

Please sign in to comment.