diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 31a687b..0395617 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -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 @@ -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 @@ -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: diff --git a/.pkgmeta b/.pkgmeta index 5c74c9c..30e541e 100644 --- a/.pkgmeta +++ b/.pkgmeta @@ -28,4 +28,5 @@ ignore: - "example*.png" - "*.toml" - "*.lock" + - "*.json" diff --git a/.scripts/post-pkg-comment.cjs b/.scripts/post-pkg-comment.cjs new file mode 100644 index 0000000..33e268e --- /dev/null +++ b/.scripts/post-pkg-comment.cjs @@ -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}`, + }); + } +}; diff --git a/package.json b/package.json index 5a5d076..903e2b5 100644 --- a/package.json +++ b/package.json @@ -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",