Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add ci INTER-353 #18

Merged
merged 24 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c118ac2
chore: add ci
Orkuncakilkaya Oct 30, 2023
c1e4f71
chore: replace deprecated set-env with echo
Orkuncakilkaya Oct 30, 2023
e38cbfa
chore: change substitution
Orkuncakilkaya Oct 30, 2023
8fcb81a
chore: use extract output
Orkuncakilkaya Oct 30, 2023
c8364e3
chore: add cloudflare dns record step to ci
Orkuncakilkaya Oct 30, 2023
78df518
chore: replace special chars on branch name
Orkuncakilkaya Oct 31, 2023
821327d
chore: fix bash
Orkuncakilkaya Oct 31, 2023
779954a
chore: fix bash
Orkuncakilkaya Oct 31, 2023
4a5daa8
chore: use action instead of curl
Orkuncakilkaya Oct 31, 2023
f26e967
chore: check dns record before create
Orkuncakilkaya Oct 31, 2023
efcb510
chore: add akamai create property step
Orkuncakilkaya Oct 31, 2023
d0bf36c
chore: add akamai scripts to ci
Orkuncakilkaya Oct 31, 2023
2bcc533
chore: fix env on ci workflow
Orkuncakilkaya Oct 31, 2023
4e50d8c
chore: change env structure on ci workflow
Orkuncakilkaya Oct 31, 2023
0eb6110
chore: add edgehostname create step
Orkuncakilkaya Oct 31, 2023
42f86fd
chore: add deploy script to ci
Orkuncakilkaya Oct 31, 2023
e0bf0a3
chore: update ci scripts & workflow
Orkuncakilkaya Nov 6, 2023
e375be5
chore: add proxy secret to build step
Orkuncakilkaya Nov 6, 2023
6ab2ff0
chore: add default paths to build step
Orkuncakilkaya Nov 6, 2023
e8b911a
chore: fix proxy_secret on build step
Orkuncakilkaya Nov 6, 2023
34d36f8
chore: ci workflow only runs when property or build changes
Orkuncakilkaya Nov 7, 2023
cdde0cc
chore: add FPJS_CI_DOMAIN secret
Orkuncakilkaya Nov 7, 2023
9392c31
chore: add FPJS_CI_DOMAIN secret to env
Orkuncakilkaya Nov 7, 2023
ca64ee5
chore: add ci cleanup workflow
Orkuncakilkaya Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/ci-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI Cleanup
on:
delete:

jobs:
cleanup:
runs-on: ubuntu-20.04
steps:
- name: Extract Branch Name
id: extract-branch
run: |
echo BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/\W/-/g and s/-+$//g') >> $GITHUB_OUTPUT
- name: Check If DNS Record Exists
id: cloudflare-dns-check
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records?name=${{steps.extract-branch.outputs.BRANCH_NAME}}.${{secrets.FPJS_CI_DOMAIN}}&tags=owner:akamai-integration-ci'
method: 'GET'
customHeaders: '{"X-Auth-Email": "${{ secrets.CF_AUTH_EMAIL }}", "Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
- name: Delete Cloudflare DNS Record
if: ${{ fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count < 1 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records/${{ fromJson(steps.cloudflare-dns-check.outputs.response).result[0].id }}'
method: 'DELETE'
customHeaders: '{"X-Auth-Email": "${{ secrets.CF_AUTH_EMAIL }}", "Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: CI
on:
push:
branches:
- '**'
- '!main'
paths:
- 'assets/**'
- 'generators/**'
- 'build.ts'

jobs:
ci:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
- name: Install dependencies
run: yarn install
- name: Extract Branch Name
id: extract-branch
run: |
echo BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/\W/-/g and s/-+$//g') >> $GITHUB_OUTPUT
- name: Check If DNS Record Exists
id: cloudflare-dns-check
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records?name=${{steps.extract-branch.outputs.BRANCH_NAME}}.${{secrets.FPJS_CI_DOMAIN}}'
method: 'GET'
customHeaders: '{"X-Auth-Email": "${{ secrets.CF_AUTH_EMAIL }}", "Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
- name: Create Cloudflare DNS Record
if: ${{ fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count < 1 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records'
method: 'POST'
customHeaders: '{"X-Auth-Email": "${{ secrets.CF_AUTH_EMAIL }}", "Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
data: '{"content": "${{steps.extract-branch.outputs.BRANCH_NAME}}.${{secrets.FPJS_CI_DOMAIN}}.edgesuite.net", "name": "${{steps.extract-branch.outputs.BRANCH_NAME}}.${{secrets.FPJS_CI_DOMAIN}}", "proxied": false, "type": "CNAME", "comment": "Akamai CI run for ${{steps.extract-branch.outputs.BRANCH_NAME}}", "ttl": 3600, "tags": ["owner:akamai-integration-ci"]}'
- name: Check Akamai Property can be created
id: check-akamai-property
continue-on-error: true
env:
BRANCH_NAME: '${{steps.extract-branch.outputs.BRANCH_NAME}}'
AK_HOST: '${{secrets.AK_HOST}}'
AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}'
AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}'
AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}'
AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}'
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
run: yarn ts-node scripts/checkPropertyCanBeCreated.ts
- name: Create Akamai Property
if: steps.check-akamai-property.outcome == 'success'
id: create-akamai-property
env:
BRANCH_NAME: '${{steps.extract-branch.outputs.BRANCH_NAME}}'
AK_HOST: '${{secrets.AK_HOST}}'
AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}'
AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}'
AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}'
AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}'
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
run: yarn ts-node scripts/createProperty.ts
- name: Build Patch Body
run: yarn build --type patchBody --proxy-secret ${{secrets.FPJS_PROXY_SECRET}} --integration-path worker --agent-path pxdownload --result-path pxresult
- name: Deploy Akamai Rules
id: deploy-rules
env:
BRANCH_NAME: '${{steps.extract-branch.outputs.BRANCH_NAME}}'
AK_HOST: '${{secrets.AK_HOST}}'
AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}'
AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}'
AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}'
AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}'
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
run: yarn ts-node scripts/deployRules.ts
17 changes: 12 additions & 5 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ const args = arg({

args['--type'] = args['--type'] ? args['--type'] : 'all'

const patchBody = () => {
export interface PatchBodyArgs {
integrationPath: string,
agentPath: string,
resultPath: string,
proxySecret: string,
}

export const patchBody = (_args?: PatchBodyArgs) => {
const bodyContent = generatePatchBody({
integrationPath: args["--integration-path"],
agentPath: args["--agent-path"],
resultPath: args["--result-path"],
proxySecret: args["--proxy-secret"],
integrationPath: args["--integration-path"] ?? _args?.integrationPath,
agentPath: args["--agent-path"] ?? _args?.agentPath,
resultPath: args["--result-path"] ?? _args?.resultPath,
proxySecret: args["--proxy-secret"] ?? _args?.proxySecret,
})

fs.mkdirSync(path.relative(process.cwd(), 'dist/patch-body'), {recursive: true})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.4.4",
"@playwright/test": "^1.39.0",
"akamai-edgegrid": "^3.4.3",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.3.1",
Expand Down
16 changes: 16 additions & 0 deletions scripts/checkPropertyCanBeCreated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {getProperty} from "./utils/getProperty";

const handler = async () => {
try {
const property = await getProperty();
if (property) {
console.log('Property already exists');
process.exit(1);
}
} catch (e) {
console.log('Error during property check:', e);
process.exit(1);
}
}

handler().finally();
122 changes: 122 additions & 0 deletions scripts/createProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import {akamaiRequest} from "./utils/akamaiRequest";
import {getProperty} from "./utils/getProperty";
import {CI_DOMAIN} from "./utils/constants";

const createProperty = async () => {
await akamaiRequest({
path: `/papi/v1/properties?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`,
method: 'POST',
body: JSON.stringify({
productId: "Site_Accel",
propertyName: CI_DOMAIN,
ruleFormat: "latest"
})
});
const {propertyId} = await getProperty();
return propertyId;
}

const createEdgeHostname = async () => {
await akamaiRequest({
path: `/papi/v1/edgehostnames?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`,
method: 'POST',
body: JSON.stringify({
ipVersionBehavior: 'IPV4',
domainPrefix: CI_DOMAIN,
domainSuffix: `edgesuite.net`,
productId: `Site_Accel`,
})
});

return findEdgeHostname()
}

const createCPCode = async () => {
let cpcodeId = await findCpcode();
if (!cpcodeId) {
await akamaiRequest({
path: `/papi/v1/cpcodes?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`,
method: 'POST',
body: JSON.stringify({
cpcodeName: CI_DOMAIN,
productId: `Site_Accel`,
}),
});
}

return findCpcode()
}

const findCpcode = async () => {
const {body: {cpcodes: {items}}} = await akamaiRequest({
path: `/papi/v1/cpcodes?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`,
method: 'GET',
});

const cpcode = items.find(t => t.cpcodeName === CI_DOMAIN);
return cpcode?.cpcodeId;
};

const patchCpcode = async (propertyId: string, cpcodeId: string) => akamaiRequest({
path: `/papi/v1/properties/${propertyId}/versions/1/rules?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`,
method: 'PATCH',
headers: {
"Content-Type": "application/json-patch+json",
},
body: [
{
op: "replace",
path: "/rules/children/0/children/0/behaviors/0/options",
value: {
value: {
id: Number(cpcodeId.replace('cpc_', '')),
},
}
}
]
});

const findEdgeHostname = async () => {
const {body: {edgeHostnames: {items}}} = await akamaiRequest({
path: `/papi/v1/edgehostnames?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`,
method: 'GET',
});
return items.find(t => t.domainPrefix === CI_DOMAIN);
}

const patchEdgeHostname = async (propertyId: string) => {
await akamaiRequest({
path: `/papi/v1/properties/${propertyId}/versions/1/hostnames`,
method: 'PATCH',
body: JSON.stringify({
"add": [
{
"cnameType": "EDGE_HOSTNAME",
"cnameFrom": CI_DOMAIN,
"cnameTo": `${CI_DOMAIN}.edgesuite.net`
},
]
})
})
};

const handler = async () => {
try {
let {propertyId} = await getProperty();
if (!propertyId) {
propertyId = await createProperty();
}
const hostname = await findEdgeHostname();
if (!hostname) {
await createEdgeHostname();
}
await patchEdgeHostname(propertyId);
const cpcodeId = await createCPCode();
await patchCpcode(propertyId, cpcodeId);
} catch (e: any) {
console.error(e)
process.exit(1);
}
}

handler().finally();
Loading
Loading