Skip to content

Commit

Permalink
Print markdown at the end of AWS job
Browse files Browse the repository at this point in the history
Signed-off-by: peterdeme <[email protected]>
  • Loading branch information
peterdeme committed Nov 20, 2023
1 parent 8580947 commit 4843365
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .github/workflows/build_aws_scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,64 @@ jobs:
PKR_VAR_ami_name_prefix: spacelift-${{ needs.timestamp.outputs.timestamp }}
PKR_VAR_source_ami_architecture: ${{ matrix.arch }}
PKR_VAR_instance_type: ${{ matrix.arch == 'x86_64' && 't3.micro' || 't4g.micro' }}

print-markdown:
needs: [build]
name: Print the AMI IDs in a markdown format
runs-on: ubuntu-latest
steps:
- name: Download x64 manifest
uses: actions/download-artifact@v3
with:
name: manifest_aws_x86_64.json
path: manifest_aws_x86_64.json

- name: Download arm64 manifest
uses: actions/download-artifact@v3
with:
name: manifest_aws_arm64.json
path: manifest_aws_arm64.json

# The manifest file look like this:
# "builds": [
# {
# "name": "spacelift",
# "builder_type": "amazon-ebs",
# "build_time": 1698670371,
# "files": null,
# "artifact_id": "ap-northeast-1:ami-0facbd2b91807c339,ap-northeast-2:ami-03849b8d23619dfb2,...
# }
# ]

- name: Print in a markdown format
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
var content = fs.readFileSync("./manifest_aws_arm64.json", "utf8");
var manifest = JSON.parse(content);
const toPrint = [];
manifest["builds"].forEach((build) => {
const regionToAmi = build["artifact_id"].split(",");
regionToAmi.forEach((regionToAmi) => {
const [region, ami] = regionToAmi.split(":");
toPrint.push(`| ${region} | ${ami} |`);
});
});
content = fs.readFileSync("./manifest_aws_x86_64.json", "utf8");
manifest = JSON.parse(content);
manifest["builds"].forEach((build) => {
const regionToAmi = build["artifact_id"].split(",");
regionToAmi.forEach((regionToAmi, i) => {
const [region, ami] = regionToAmi.split(":");
toPrint[i] = toPrint[i] + ` ${ami} |`;
});
});
console.log("| AWS Region | AMI ID (ARM64) | AMI ID (x86_64) |");
console.log("|------------------|-------------------------|-------------------------|");
toPrint.forEach(line => console.log(line));
70 changes: 70 additions & 0 deletions .github/workflows/build_gcp_azure_manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,73 @@ jobs:
path: manifest_${{ matrix.cloud }}.json
name: manifest_${{ matrix.cloud }}.json
retention-days: 5

print-markdown:
needs: [build]
name: Print the AMI IDs in a markdown format
runs-on: ubuntu-latest
steps:
- name: Download Google Cloud manifest
uses: actions/download-artifact@v3
with:
name: manifest_gcp.json
path: manifest_gcp.json

# The GCP manifest file look like this:
# "builds": [
# {
# "name": "spacelift",
# "builder_type": "googlecompute",
# "build_time": 1700479054,
# "files": null,
# "artifact_id": "spacelift-worker-us-1700478848-305dsvij",
# "packer_run_uuid": "cdc82943-986b-5ab9-6ce1-9024ca0ebb6a",
# "custom_data": null
# },
# {
# "name": "spacelift",
# "builder_type": "googlecompute",
# "build_time": 1700479263,
# "files": null,
# "artifact_id": "spacelift-worker-eu-1700478848-305dsvij",
# "packer_run_uuid": "2440c9b1-a342-3606-2661-6e5389bdffc6",
# "custom_data": null
# }
# ]

- name: Print in a markdown format
uses: actions/github-script@v6
env:
RUN_NUMBER: ${{ github.run_number }}
with:
script: |
const fs = require("fs");
content = fs.readFileSync("./manifest_gcp.json", "utf8");
manifest = JSON.parse(content);
const gcpLinesToPrint = [];
manifest["builds"].forEach((build) => {
artifact = build["artifact_id"];
if (artifact.indexOf("-us-") > 0) {
gcpLinesToPrint.push(` - United States | \`${artifact}\``);
}
if (artifact.indexOf("-eu-") > 0) {
gcpLinesToPrint.push(` - Europe | \`${artifact}\``);
}
if (artifact.indexOf("-asia-") > 0) {
gcpLinesToPrint.push(` - Asia | \`${artifact}\``);
}
});
console.log("## Azure");
console.log("");
console.log(`- Publisher | \`spaceliftinc1625499025476\`.`);
console.log(`- Offer | \`spacelift_worker\`.`);
console.log(`- SKU | \`ubuntu_20_04\`.`);
console.log(`- Version | \`1.0.${process.env.RUN_NUMBER}\`.`);
console.log("");
console.log("## Google Cloud Platform");
console.log("");
gcpLinesToPrint.forEach(line => console.log(line));
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: 👷 ${{ matrix.cloud }}
strategy:
matrix:
cloud: [aws, aws_minimal, azure, gcp]
cloud: [aws, azure, gcp]
runs-on: ubuntu-latest
env:
# AWS
Expand Down

0 comments on commit 4843365

Please sign in to comment.