Skip to content

Commit

Permalink
build: ignores json files in packaging (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mctalian authored Jan 5, 2025
1 parent 27935d8 commit dc67f33
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 30 deletions.
54 changes: 24 additions & 30 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ jobs:
if: env.IS_FORK == 'true'
uses: actions/checkout@v4

- name: Fetch Latest Release Assets
id: fetch-release-assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
nolib_size=$(gh release view --json assets -q '.assets[] | select(.name | endswith("nolib.zip")) | .size')
echo "NoLibSize: $nolib_size"
lib_size=$(gh release view --json assets -q '.assets[] | select(.name | endswith(".zip")) | select(.name | contains("-nolib") | not) | .size')
echo "LibSize: $lib_size"
echo "LATEST_RELEASE_NOLIB_SIZE=$nolib_size" >> $GITHUB_ENV
echo "LATEST_RELEASE_LIBS_SIZE=$lib_size" >> $GITHUB_ENV
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: subversion
Expand All @@ -114,6 +126,8 @@ jobs:
FILE2=$(ls .release/RPGLootFeed-*.zip | grep -v 'nolib')
echo "FILE1=$FILE1" >> $GITHUB_ENV
echo "FILE2=$FILE2" >> $GITHUB_ENV
echo "TEST_NOLIB_SIZE=$(stat -c%s "$FILE1")" >> $GITHUB_ENV
echo "TEST_LIBS_SIZE=$(stat -c%s "$FILE2")" >> $GITHUB_ENV
- name: Upload RPGLootFeed ZIP
uses: actions/upload-artifact@v4
Expand All @@ -134,38 +148,18 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const commentIdentifier = "### Packaged ZIP files"; // Unique phrase to identify the comment
const linkStandard = `[RPGLootFeed ZIP (with libs)](${{ steps['upload-zips-standard'].outputs.artifact-url }})`;
const linkNolib = `[RPGLootFeed ZIP (nolib)](${{ steps['upload-zips-nolib'].outputs.artifact-url }})`;
const lastUpdated = new Date().toLocaleString('en-US', { timeZone: 'UTC', hour12: true });
const commentBody = `${linkStandard}\n${linkNolib}\n\nLast Updated: ${lastUpdated} (UTC)`;
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
const script = require('./.scripts/post-pkg-comment.cjs');
await script({
github,
context,
libsUrl: "${{ steps['upload-zips-standard'].outputs.artifact-url }}",
noLibUrl: "${{ steps['upload-zips-nolib'].outputs.artifact-url }}",
latestReleaseStandardSize: process.env.LATEST_RELEASE_LIBS_SIZE,
testPkgStandardSize: process.env.TEST_LIBS_SIZE,
latestReleaseNoLibSize: process.env.LATEST_RELEASE_NOLIB_SIZE,
testPkgNoLibSize: process.env.TEST_NOLIB_SIZE
});
const existingComment = comments.find(comment => comment.body.includes(commentIdentifier));
if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${commentIdentifier}\n${commentBody}`
});
} else {
// Create a new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${commentIdentifier}\n${commentBody}`
});
}
commitlint:
runs-on: ubuntu-latest
env:
Expand Down
1 change: 1 addition & 0 deletions .pkgmeta
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ ignore:
- "example*.png"
- "*.toml"
- "*.lock"
- "*.json"

76 changes: 76 additions & 0 deletions .scripts/post-pkg-comment.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module.exports = async ({
github,
context,
noLibUrl,
libsUrl,
latestReleaseStandardSize,
testPkgStandardSize,
latestReleaseNoLibSize,
testPkgNoLibSize,
}) => {
const commentIdentifier = "### Packaged ZIP files"; // Unique phrase to identify the comment
const linkStandard = `[RPGLootFeed ZIP (with libs)](${libsUrl})`;
const linkNolib = `[RPGLootFeed ZIP (nolib)](${noLibUrl})`;

const standardSizeDeltaPct =
((testPkgStandardSize - latestReleaseStandardSize) /
latestReleaseStandardSize) *
100;
const standardSize = `(${latestReleaseStandardSize} ➡️ ${testPkgStandardSize}, ${standardSizeDeltaPct.toFixed(2)}%)`;
const noLibSizeDeltaPct =
((testPkgNoLibSize - latestReleaseNoLibSize) / latestReleaseNoLibSize) *
100;
const noLibSize = `(${latestReleaseNoLibSize} ➡️ ${testPkgNoLibSize}, ${noLibSizeDeltaPct.toFixed(2)}%)`;
let stdSizeWarning = "";
if (standardSizeDeltaPct > 5) {
stdSizeWarning = "⚠️";
} else if (standardSizeDeltaPct < 0) {
stdSizeWarning = "🟢";
}

let noLibSizeWarning = "";
if (noLibSizeDeltaPct > 5) {
noLibSizeWarning = "⚠️";
} else if (noLibSizeDeltaPct < 0) {
noLibSizeWarning = "🟢";
}

const lastUpdated = new Date().toLocaleString("en-US", {
timeZone: "UTC",
hour12: true,
});
const commentBody = `
${linkStandard} ${standardSize} ${stdSizeWarning}
${linkNolib} ${noLibSize} ${noLibSizeWarning}
Last Updated: ${lastUpdated} (UTC)
`;

const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});

const existingComment = comments.find((comment) =>
comment.body.includes(commentIdentifier),
);

if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${commentIdentifier}\n${commentBody}`,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${commentIdentifier}\n${commentBody}`,
});
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "rpglootfeed",
"version": "1.0.0",
"description": "[WOW ADDON] A non-intrusive way to see what you just looted in World of Warcraft.",
"type": "module",
"main": "index.js",
"scripts": {
"test": "make test",
Expand Down

0 comments on commit dc67f33

Please sign in to comment.