forked from aws/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mainline' into mainline
- Loading branch information
Showing
21 changed files
with
859 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: Compute bin sizes | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
|
||
jobs: | ||
binsize: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
|
||
- name: Set up Node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Get latest release with tag | ||
id: latestrelease | ||
run: | | ||
echo "VERSION_TAG=$(curl -s https://api.github.com/repos/aws/copilot-cli/releases/latest | jq '.tag_name' | sed 's/\"//g')" >> $GITHUB_OUTPUT | ||
- name: Check out latest release tag | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ steps.latestrelease.outputs.VERSION_TAG }} | ||
repository: aws/copilot-cli | ||
|
||
- name: Compute old release binary sizes | ||
id: old-bins | ||
run: | | ||
make release | ||
echo "MAC_AMD_KIB=$(du -k ./bin/local/copilot-darwin-amd64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "MAC_ARM_KIB=$(du -k ./bin/local/copilot-darwin-arm64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "LINUX_AMD_KIB=$(du -k ./bin/local/copilot-linux-amd64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "LINUX_ARM_KIB=$(du -k ./bin/local/copilot-linux-arm64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "WINDOWS_AMD_KIB=$(du -k ./bin/local/copilot.exe | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
- name: Check out PR commit | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Compute new release binary sizes | ||
id: new-bins | ||
run: | | ||
make release | ||
echo "MAC_AMD_KIB=$(du -k ./bin/local/copilot-darwin-amd64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "MAC_ARM_KIB=$(du -k ./bin/local/copilot-darwin-arm64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "LINUX_AMD_KIB=$(du -k ./bin/local/copilot-linux-amd64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "LINUX_ARM_KIB=$(du -k ./bin/local/copilot-linux-arm64 | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
echo "WINDOWS_AMD_KIB=$(du -k ./bin/local/copilot.exe | awk '{ print $1}')" >> $GITHUB_OUTPUT | ||
- name: Save sizes and PR number | ||
run: | | ||
mkdir artifacts | ||
sizes_json="{ | ||
\"macOS\": { | ||
\"amd\": { | ||
\"old\": ${{ steps.old-bins.outputs.MAC_AMD_KIB }}, | ||
\"cur\": ${{ steps.new-bins.outputs.MAC_AMD_KIB }} | ||
}, | ||
\"arm\": { | ||
\"old\": ${{ steps.old-bins.outputs.MAC_ARM_KIB }}, | ||
\"cur\": ${{ steps.new-bins.outputs.MAC_ARM_KIB }} | ||
} | ||
}, | ||
\"linux\": { | ||
\"amd\": { | ||
\"old\": ${{ steps.old-bins.outputs.LINUX_AMD_KIB }}, | ||
\"cur\": ${{ steps.new-bins.outputs.LINUX_AMD_KIB }} | ||
}, | ||
\"arm\": { | ||
\"old\": ${{ steps.old-bins.outputs.LINUX_ARM_KIB }}, | ||
\"cur\": ${{ steps.new-bins.outputs.LINUX_ARM_KIB }} | ||
} | ||
}, | ||
\"windows\": { | ||
\"amd\": { | ||
\"old\": ${{ steps.old-bins.outputs.WINDOWS_AMD_KIB }}, | ||
\"cur\": ${{ steps.new-bins.outputs.WINDOWS_AMD_KIB }} | ||
} | ||
} | ||
}" | ||
echo ${{ github.event.number }} > artifacts/pr_number | ||
echo ${sizes_json} > artifacts/sizes.json | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: pr_number_and_bin_sizes | ||
path: artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
name: Comment PR with bin sizes | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Compute bin sizes"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
comment_bin_size: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.payload.workflow_run.id, | ||
}); | ||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "pr_number_and_bin_sizes" | ||
})[0]; | ||
let download = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifacts.zip`, Buffer.from(download.data)); | ||
- name: Unzip artifacts | ||
run: unzip artifacts.zip | ||
|
||
- name: Calculate size change | ||
id: diff | ||
uses: actions/github-script@v6 | ||
with: | ||
result-encoding: string | ||
script: | | ||
let fs = require('fs'); | ||
let sizes_raw = fs.readFileSync('sizes.json'); | ||
let sizes = JSON.parse(sizes_raw) | ||
const diff = (old, cur) => { | ||
const res = (cur-old)/old * 100; | ||
return res.toFixed(2); // 2 decimal places. | ||
}; | ||
const lastRelease = '${{ steps.latestrelease.outputs.VERSION_TAG }}'; | ||
let msg = ` | ||
🍕 Here are the new binary sizes! | ||
| Name | New size (kiB) | ${lastRelease} size (kiB) | Delta (%) | | ||
|:-- |:--- |:--- |:-- | | ||
`; | ||
let shouldAcknowledgeSize = false; | ||
for (const os of Object.keys(sizes)) { | ||
for (const arch of Object.keys(sizes[os])) { | ||
const delta = diff(sizes[os][arch].old, sizes[os][arch].cur); | ||
if (delta > 10) { | ||
shouldAcknowledgeSize = true; | ||
} | ||
let symbol = "❤️ "; | ||
if (delta > 5) { | ||
symbol = "😭 +"; | ||
} else if (delta > 1) { | ||
symbol = "🥺 +" | ||
} else if (delta > 0) { | ||
symbol = "+"; | ||
} | ||
msg += `| ${os} (${arch}) | ${sizes[os][arch].cur} | ${sizes[os][arch].old} | ${symbol}${delta} |` + "\n"; | ||
} | ||
} | ||
if (shouldAcknowledgeSize) { | ||
msg += "**The binary size increased more than expected! Applying the `do-not-merge` label.**\n" | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['do-not-merge'] | ||
}); | ||
} | ||
return msg; | ||
- name: Find PR number | ||
id: find-pr-number | ||
run: | | ||
echo "PR_NUMBER=$(cat pr_number)" >> $GITHUB_OUTPUT | ||
- name: Find comment | ||
uses: peter-evans/find-comment@v2 | ||
id: fc | ||
with: | ||
issue-number: ${{ steps.find-pr-number.outputs.PR_NUMBER }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: 'Here are the new binary sizes' | ||
|
||
- name: Create or update comment | ||
uses: peter-evans/create-or-update-comment@v2 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ steps.find-pr-number.outputs.PR_NUMBER }} | ||
body: ${{ steps.diff.outputs.result }} | ||
edit-mode: replace |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.