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 a3c6c03
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
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));
48 changes: 48 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,51 @@ 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 Azure manifest
uses: actions/download-artifact@v3
with:
name: manifest_azure.json
path: manifest_azure.json

- name: Download Google Cloud manifest
uses: actions/download-artifact@v3
with:
name: manifest_gcp.json
path: manifest_gcp.json

# Enable this once we know the final format
- name: Print in a markdown format
if: false
uses: actions/github-script@v6
with:
script: |
import { readFileSync } from 'fs';
var content = readFileSync("./manifest_azure.json", "utf8");
var manifest = JSON.parse(content);
const azureVersion = manifest["builds"][0]["artifact_id"].split(":")[1];
content = readFileSync("./manifest_gcp.json", "utf8");
manifest = JSON.parse(content);
const gcpVersion = manifest["builds"][0]["artifact_id"].split(":")[1];
console.log("## Azure");
console.log("");
console.log(`- Publisher | \`spaceliftinc1625499025476\`.`);
console.log(`- Offer | \`spacelift_worker\`.`);
console.log(`- SKU | \`ubuntu_20_04\`.`);
console.log(`- Version | \`${azureVersion}\`.`);
console.log("");
console.log("## Google Cloud Platform");
console.log("");
console.log(`- United States | \`spacelift-worker-us-1698150055-${gcpVersion}\``);
console.log(`- Europe | \`spacelift-worker-eu-1698150055-${gcpVersion}\``);
console.log(`- Asia | \`spacelift-worker-asia-1698150055-${gcpVersion}\``);

0 comments on commit a3c6c03

Please sign in to comment.