Skip to content

ci(release): compact marker subject, skip CI on marker, filter prior … #1884

ci(release): compact marker subject, skip CI on marker, filter prior …

ci(release): compact marker subject, skip CI on marker, filter prior … #1884

Workflow file for this run

name: Non Regression Testing (US)
on:
workflow_dispatch:
schedule:
- cron: "0 9 * * 1-5"
push:
branches: [ main ]
permissions:
contents: read
jobs:
log-context:
runs-on: ubuntu-latest
steps:
# Dump all contexts
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
create-system-identity:
name: Create System Identity
runs-on: ubuntu-latest
outputs:
CLIENT_ID: ${{ steps.create-us-identity.outputs.CLIENT_ID }}
CLIENT_SECRET: ${{ steps.create-us-identity.outputs.CLIENT_SECRET }}
SYSTEM_IDENTITY_ID: ${{ steps.create-us-identity.outputs.SYSTEM_IDENTITY_ID }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Write Test Definition File JSON to file
env:
USER_JSON: ${{ secrets.GIT_DEPLOYER_DOCKER_USER_CONFIG }}
run: |
mkdir -p configs
echo "$USER_JSON" > configs/gitusdkr${{ github.run_id }}.json
- name: Extract New Relic Credentials (US)
id: extract-nr-creds
run: |
NR_API_KEY=$(jq -r -e '.credentials.newrelic.nrPersonalApiKey' configs/gitusdkr${{ github.run_id }}.json)
NR_ORG_ID=$(jq -r -e '.credentials.newrelic.nrOrganizationId' configs/gitusdkr${{ github.run_id }}.json)
echo "::add-mask::$NR_API_KEY"
echo "::add-mask::$NR_ORG_ID"
echo "NR_API_KEY=$NR_API_KEY" >> $GITHUB_OUTPUT
echo "NR_ORG_ID=$NR_ORG_ID" >> $GITHUB_OUTPUT
- name: Create System Identity for US Region
id: create-us-identity
run: |
RESPONSE=$(curl -X POST https://api.newrelic.com/graphql \
-H 'content-type: application/json; charset=utf-8' \
-H "API-Key: ${{ steps.extract-nr-creds.outputs.NR_API_KEY }}" \
--data-raw "{
\"query\": \"mutation { systemIdentityCreate( name: \\\"open-install-library-e2e-us\\\" organizationId: \\\"${{ steps.extract-nr-creds.outputs.NR_ORG_ID }}\\\" ) { id clientId clientSecret } }\"
}")
CLIENT_ID=$(echo "$RESPONSE" | jq -e -r '.data.systemIdentityCreate.clientId')
CLIENT_SECRET=$(echo "$RESPONSE" | jq -e -r '.data.systemIdentityCreate.clientSecret')
SYSTEM_IDENTITY_ID=$(echo "$RESPONSE" | jq -e -r '.data.systemIdentityCreate.id')
echo "CLIENT_ID=$CLIENT_ID" >> $GITHUB_OUTPUT
echo "CLIENT_SECRET=$CLIENT_SECRET" >> $GITHUB_OUTPUT
echo "SYSTEM_IDENTITY_ID=$SYSTEM_IDENTITY_ID" >> $GITHUB_OUTPUT
- name: Get NR Control Group ID
id: get-nr-control-group
run: |
RESPONSE=$(curl -X POST https://api.newrelic.com/graphql \
-H 'content-type: application/json; charset=utf-8' \
-H "API-Key: ${{ steps.extract-nr-creds.outputs.NR_API_KEY }}" \
--data-raw "{
\"query\": \"query getSystemIdentityGroupsQuery(\$organizationId: ID!, \$name: String!) { customerAdministration { systemIdentityGroups(filter: {name: {eq: \$name}, organizationId: {eq: \$organizationId}}) { items { id } totalCount } } }\",
\"variables\": { \"organizationId\": \"${{ steps.extract-nr-creds.outputs.NR_ORG_ID }}\", \"name\": \"NR Control Group\" }
}")
GROUP_ID=$(echo "$RESPONSE" | jq -e -r '.data.customerAdministration.systemIdentityGroups.items[0].id')
echo "GROUP_ID=$GROUP_ID" >> $GITHUB_OUTPUT
- name: Add System Identity to NR Control Group
if: steps.get-nr-control-group.outputs.GROUP_ID != ''
run: |
curl -X POST https://api.newrelic.com/graphql \
-H 'content-type: application/json; charset=utf-8' \
-H "API-Key: ${{ steps.extract-nr-creds.outputs.NR_API_KEY }}" \
--data-raw "{
\"query\": \"mutation createSystemIdentityAddToGroupsMutation(\$systemIdentityIds: [ID!]!, \$systemIdentityGroupIds: [ID!]!) { systemIdentityAddToGroups(systemIdentityIds: \$systemIdentityIds, systemIdentityGroupIds: \$systemIdentityGroupIds) { systemIdentityGroups { id } } }\",
\"variables\": { \"systemIdentityIds\": [\"${{ steps.create-us-identity.outputs.SYSTEM_IDENTITY_ID }}\"], \"systemIdentityGroupIds\": [\"${{ steps.get-nr-control-group.outputs.GROUP_ID }}\"] }
}"
get-test-definition-files:
name: Get Test Definition Files
runs-on: ubuntu-latest
needs: [create-system-identity]
outputs:
matrix: ${{ steps.get-test-definition-files.outputs.result }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Test Definition Files
id: get-test-definition-files
uses: actions/github-script@v3
with:
script: |
const fs = require("fs");
const fsp = fs.promises;
const path = require("path");
const { isOHIValidationTimeout } = require("${{ github.workspace }}/.github/workflows/scripts/ohiValidationTimeout");
// readdir recursive directory search
const { readdir } = fsp;
async function getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(
dirents.map((dirent) => {
const res = path.join(dir, dirent.name);
return dirent.isDirectory() ? getFiles(res) : res;
})
);
return Array.prototype.concat(...files);
}
const definitionsDir = "test/definitions";
let testDefinitions = await getFiles(definitionsDir);
// Tests in this list will be skipped.
const excludedListPath = path.join(process.env.GITHUB_WORKSPACE, '.github', 'deprecated-tests.json');
let excludedTests = [];
try {
const data = require(excludedListPath);
excludedTests = Array.isArray(data) ? data : (Array.isArray(data.exclude) ? data.exclude : []);
console.log('Excluded tests loaded:', excludedTests);
} catch (err) {
// If file missing or invalid, proceed without exclusions.
console.log('Excluded tests file not loaded (missing or invalid). Proceeding without exclusions. Reason:', err.message);
}
if (excludedTests.length) {
const beforeCount = testDefinitions.length;
testDefinitions = testDefinitions.filter(f => !excludedTests.includes(f));
console.log(`Filtered ${beforeCount - testDefinitions.length} tests from test definitions.`);
}
const outputTestFilesMap = testDefinitions
.filter((testDefinitionFile) => !isOHIValidationTimeout(testDefinitionFile))
.map((testDefinitionFile) => {
return {
testDefinitionFile,
testDisplayName: testDefinitionFile.replace(`${definitionsDir}/`, ""),
};
});
const output = {
include: outputTestFilesMap,
};
console.log(output);
return output;
test-deploy-recipe:
name: ${{ matrix.testDisplayName }}
needs: [get-test-definition-files, create-system-identity]
if: ${{ fromJSON(needs.get-test-definition-files.outputs.matrix).include[0] }}
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.get-test-definition-files.outputs.matrix) }}
fail-fast: false
env:
MATRIX: ${{ toJSON(matrix) }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Mask and set system identity credentials
run: |
echo "::add-mask::${{ needs.create-system-identity.outputs.CLIENT_ID }}"
echo "::add-mask::${{ needs.create-system-identity.outputs.CLIENT_SECRET }}"
echo "SYSTEM_IDENTITY_CLIENT_ID=${{ needs.create-system-identity.outputs.CLIENT_ID }}" >> $GITHUB_ENV
echo "SYSTEM_IDENTITY_CLIENT_SECRET=${{ needs.create-system-identity.outputs.CLIENT_SECRET }}" >> $GITHUB_ENV
- name: Update Test Definition Files URLs
id: get-test-definition-files
env:
TEST_DEFINITION_FILE: ${{ matrix.testDefinitionFile }}
uses: actions/github-script@v3
with:
script: |
const fs = require('fs');
const fsp = fs.promises;
const path = require('path');
// before returning, we need to edit the deploy config files in-place so they
// use the right URLs from the branch
async function getDeployConfigFile(file, outputDir) {
const data = await fsp.readFile(path.join(outputDir, file));
return JSON.parse(data);
}
// Get testDefinitonFile from MATRIX env var
const testDefinitionFile = process.env.TEST_DEFINITION_FILE;
console.log(`Detected Deploy Config: ${JSON.stringify(testDefinitionFile, null, 2)}`)
// Update URLs to use branch this PR is opened with
const data = await getDeployConfigFile(testDefinitionFile, process.env.GITHUB_WORKSPACE);
// Update github source URLs with branch name
let jsonContent = JSON.stringify(data, null, 2);
const branchName = process.env.GITHUB_HEAD_REF ? process.env.GITHUB_HEAD_REF : process.env.GITHUB_REF_NAME;
const replacementString = `$1$2-b ${branchName} $3$4`;
const sourceRepositoryRegex = /(.*)(\")(https:\/\/github.com\/newrelic\/open-install-library)(.*)/gi;
jsonContent = jsonContent.replace(sourceRepositoryRegex, replacementString);
console.log(`Detected Deploy Config: ${JSON.stringify(jsonContent, null, 2)}`)
// Update raw URLs with branch name
const replacementString2 = `$1${branchName}$3`;
const sourceRepositoryRegex2 = /(raw.githubusercontent.com\/newrelic\/open-install-library\/)(main)(\/newrelic\/recipes\/)*/gi;
jsonContent = jsonContent.replace(sourceRepositoryRegex2, replacementString2);
console.log(`Detected Deploy Config: ${JSON.stringify(jsonContent, null, 2)}`)
// Write file back to workspace
const outputPath = `${process.env.GITHUB_WORKSPACE}/${testDefinitionFile}`;
fs.writeFileSync(outputPath, jsonContent);
return testDefinitionFile;
- name: Write AWS Certificate to File
env:
AWS_PEM: ${{ secrets.GIT_DEPLOYER_CANADA_AWS_PEM }}
run: |
mkdir -p configs
rm -f configs/gitdeployerCanada.pem
echo "$AWS_PEM" > configs/gitdeployerCanada.pem
sudo chmod 400 configs/gitdeployerCanada.pem
- name: Write Test Definition File JSON to file
env:
USER_JSON: ${{ secrets.GIT_DEPLOYER_DOCKER_USER_CONFIG }}
run: |
echo "$USER_JSON" > configs/gitusdkr${{ github.run_id }}.json
- name: Pull Deployer image
run: |
docker pull newrelic/deployer:latest
docker images newrelic/deployer:latest
- name: Run deployer
id: deployerRun
run: |
set -e
testDefinitionFile=$(echo $MATRIX | jq -c -r '.testDefinitionFile')
echo $testDefinitionFile
if [[ "$testDefinitionFile" == test/definitions/agent-control/* || "$testDefinitionFile" == test/definitions-eu/agent-control/* ]]; then
docker run -i\
-e SYSTEM_IDENTITY_CLIENT_ID=$SYSTEM_IDENTITY_CLIENT_ID\
-e SYSTEM_IDENTITY_CLIENT_SECRET=$SYSTEM_IDENTITY_CLIENT_SECRET\
-v ${{ github.workspace }}/configs/:/mnt/deployer/configs/\
-v ${{ github.workspace }}/test/:/mnt/deployer/test/\
--entrypoint ruby newrelic/deployer:latest main.rb -c configs/gitusdkr${{ github.run_id }}.json -d $testDefinitionFile -l debug
else
docker run -i\
-v ${{ github.workspace }}/configs/:/mnt/deployer/configs/\
-v ${{ github.workspace }}/test/:/mnt/deployer/test/\
--entrypoint ruby newrelic/deployer:latest main.rb -c configs/gitusdkr${{ github.run_id }}.json -d $testDefinitionFile -l debug
fi
echo ::set-output name=exit_status::$?
- name: Teardown any previous deployment
if: always()
id: cleanupResources
continue-on-error: true
run: |
testDefinitionFile=$(echo $MATRIX | jq -c -r '.testDefinitionFile')
echo $testDefinitionFile
docker run \
-v ${{ github.workspace }}/configs/:/mnt/deployer/configs/\
-v ${{ github.workspace }}/test/:/mnt/deployer/test/\
--entrypoint ruby newrelic/deployer:latest main.rb -c configs/gitusdkr${{ github.run_id }}.json -d $testDefinitionFile -t
- name: Report any error
if: steps.deployerRun.outputs.exit_status != 0
run: exit 1
cleanup-system-identity:
name: Cleanup System Identity
runs-on: ubuntu-latest
needs: [test-deploy-recipe, create-system-identity]
if: always() && needs.create-system-identity.result == 'success'
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Write Test Definition File JSON to file
env:
USER_JSON: ${{ secrets.GIT_DEPLOYER_DOCKER_USER_CONFIG }}
run: |
mkdir -p configs
echo "$USER_JSON" > configs/gitusdkr${{ github.run_id }}.json
- name: Clean up system identity
continue-on-error: true
run: |
if [ -f configs/gitusdkr${{ github.run_id }}.json ]; then
NR_API_KEY=$(jq -r -e '.credentials.newrelic.nrPersonalApiKey' configs/gitusdkr${{ github.run_id }}.json)
SYSTEM_IDENTITY_ID="${{ needs.create-system-identity.outputs.SYSTEM_IDENTITY_ID }}"
echo "::add-mask::$NR_API_KEY"
echo "::add-mask::$SYSTEM_IDENTITY_ID"
if [ ! -z "$SYSTEM_IDENTITY_ID" ] && [ "$SYSTEM_IDENTITY_ID" != "null" ]; then
echo "Cleaning up system identity with ID: $SYSTEM_IDENTITY_ID"
curl -X POST https://api.newrelic.com/graphql \
-H 'content-type: application/json; charset=utf-8' \
-H "API-Key: $NR_API_KEY" \
--data-raw "{
\"query\": \"mutation { systemIdentityDelete(id: \\\"$SYSTEM_IDENTITY_ID\\\") { id } }\"
}" || echo "Failed to delete system identity, it may have already been deleted"
else
echo "No system identity to clean up"
fi
else
echo "Config file not found, skipping system identity cleanup"
fi
slack-notify:
runs-on: ubuntu-latest
needs: [test-deploy-recipe, cleanup-system-identity]
if: always()
steps:
- name: Build Result Slack Notification
uses: 8398a7/action-slack@v3
with:
author_name: GitHub Actions
status: custom
fields: commit,repo,ref,author,eventName,message,workflow
custom_payload: |
{
username: "GitHub Actions",
icon_emoji: ":octocat:",
attachments: [{
color: ${{
needs.test-deploy-recipe.result == 'success'
}} === true ? '#43cc11' : '#e05d44',
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: `Build for ${process.env.AS_REPO}`
}
},
{
type: "section",
fields: [
{
type: "mrkdwn",
text: `*Commit:*\n${process.env.AS_COMMIT}`
},
{
type: "mrkdwn",
text: `*Author:*\n${process.env.AS_AUTHOR}`
},
{
type: "mrkdwn",
text: `*Branch:*\n${process.env.AS_REF}`
},
{
type: "mrkdwn",
text: `*Message:*\n${process.env.AS_MESSAGE}`
},
{
type: "mrkdwn",
text: `*Type:*\n${process.env.AS_EVENT_NAME}`
},
{
type: "mrkdwn",
text: "*PR:*\n${{ github.event.pull_request.html_url }}"
},
{
type: "mrkdwn",
text: `*Workflow:*\n${ process.env.AS_WORKFLOW }`
}
]
},
{
type: "section",
text: {
type: "mrkdwn",
text: [
"*Result:*",
`• ${ ${{ needs.test-deploy-recipe.result == 'success' }} === true ? '✅' : '❌' } Non-regression testing of all recipes: ${{ needs.test-deploy-recipe.result }}`
].join('\n')
}
},
{
type: "context",
elements: [
{
type: "image",
image_url: "https://avatars2.githubusercontent.com/in/15368",
alt_text: "Github Actions"
},
{
type: "mrkdwn",
text: "This message was created automatically by GitHub Actions."
}
]
}
]
}]
}
env:
GITHUB_TOKEN: ${{ github.token }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}