Skip to content

Zip Release

Zip Release #72

Workflow file for this run

name: Zip Release
on:
schedule:
- cron: '0 8 * * 0'
workflow_dispatch:
concurrency:
group: ss_ci-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
name: CI Main
runs-on: ubuntu-latest
if: "! contains(github.event.head_commit.message, '[noci]')"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Changes
id: check_changes
uses: actions/github-script@v7
with:
script: |
if (context.eventName === "workflow_dispatch") {
core.setOutput("should_proceed", "true");
return;
}
const { owner, repo } = context.repo;
const tags = await github.rest.repos.listTags({ owner, repo });
if (tags.data.length === 0) {
core.setOutput("should_proceed", "true");
return;
}
const lastTag = tags.data[0].name;
const compare = await github.rest.repos.compareCommits({
owner,
repo,
base: lastTag,
head: "HEAD"
});
const files = compare.data.files || [];
const luaFiles = files.filter(f => f.filename.endsWith(".lua"));
core.setOutput(
"should_proceed",
luaFiles.length != 0 ? "true" : "false"
);
- name: Increment Tag
id: increment_tag
if: steps.check_changes.outputs.should_proceed == 'true'
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const tags = await github.rest.repos.listTags({ owner, repo });
let no_prefix;
let new_tag;
let old_tag;
if (tags.data.length === 0) {
new_tag = 'v1.0.0';
no_prefix = '1.0.0';
} else {
const latest = tags.data[0].name.substring(1).split('.').map(Number);
if (latest[1] === 9 && latest[2] === 9) {
latest[0] += 1; latest[1] = 0; latest[2] = 0;
} else if (latest[2] === 9) {
latest[1] += 1; latest[2] = 0;
} else {
latest[2] += 1;
}
no_prefix = latest.join('.');
new_tag = `v${latest.join('.')}`;
old_tag = tags.data[0].name;
}
core.setOutput("version_number", new_tag);
core.setOutput("no_prefix", no_prefix);
core.setOutput("old_tag", old_tag);
- name: Generate Changelog
id: changelog
if: steps.check_changes.outputs.should_proceed == 'true'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const lastTag = "${{ steps.increment_tag.outputs.old_tag }}";
const { data: tagRefs } = await github.rest.git.getRef({ owner, repo, ref: `tags/${lastTag}` });
const tagSha = tagRefs.object.sha;
const { data: tagCommit } = await github.rest.repos.getCommit({ owner, repo, ref: tagSha });
const lastTagDate = new Date(tagCommit.commit.committer.date);
const { data: pulls } = await github.rest.pulls.list({
owner, repo, state: "closed", sort: "updated", direction: "asc", per_page: 100
});
let changelog = "";
let breaking = false;
let breakingMsg = ">[!Important]\n>**This is a breaking change**\n>To install this update, please remove the previous version completely and then install the new version.\n\n";
function isBreakingChange(str) {
return str.toLowerCase().includes("breaking change");
}
const mergedPRs = pulls.filter(pr => pr.merged_at && new Date(pr.merged_at) > lastTagDate);
const extractField = (body, fieldName) => {
const regex = new RegExp(`${fieldName}:\\s*([\\s\\S]*?)(?=\\n\\w+:|$)`, 'm');
const match = body.match(regex);
if (!match)
return "";
return match[1].trim();
};
if (mergedPRs.length > 0) {
for (const pr of mergedPRs) {
changelog += `### PR #${pr.number}: ${pr.title}\n`;
const body = pr.body;
if (body) {
breaking = breaking || isBreakingChange(body);
changelog += `${body.trim()}\n\n`;
}
}
} else {
const compared = await github.rest.repos.compareCommits({
owner,
repo,
base: lastTag,
head: "main"
});
const commits = compared.data.commits;
for (const commit of commits) {
const msg = commit.commit.message || "";
const body = commit.commit.body;
if (msg.toLowerCase().startsWith("merge pull"))
continue;
breaking = breaking || isBreakingChange(msg);
changelog += `## ${msg}\n\n`;
if (body) {
breaking = breaking || isBreakingChange(body);
changelog += `${body.trim()}\n\n`;
}
}
}
if (breaking) {
changelog = `${breakingMsg}${changelog}`
}
core.setOutput("changelog", changelog);
- name: Bump Version
if: steps.check_changes.outputs.should_proceed == 'true'
run: |
sed -i "s|return \".*\"|return \"${{steps.increment_tag.outputs.no_prefix}}\"|" SSV2/includes/version.lua
sed -i "s|https://img.shields.io/badge/Script%20Version-v[0-9]\+\.[0-9]\+\.[0-9]\+-blue|https://img.shields.io/badge/Script%20Version-${{steps.increment_tag.outputs.version_number}}-blue|g" README.md
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add SSV2/includes/version.lua README.md
git diff --cached --quiet || git commit -m "[noci] bump version"
git push
- name: Create Archive
if: steps.check_changes.outputs.should_proceed == 'true'
uses: thedoctor0/zip-release@0.7.6
with:
type: 'zip'
filename: "Samurais_Scripts_${{ steps.increment_tag.outputs.version_number }}.zip"
exclusions: /.git* /scripts* /docs* *.json *.md *.editorconfig *.py *.txt LICENSE
- name: Upload Release
if: steps.check_changes.outputs.should_proceed == 'true'
uses: softprops/action-gh-release@v2
with:
name: Samurai's Scripts ${{ steps.increment_tag.outputs.version_number }}
tag_name: ${{ steps.increment_tag.outputs.version_number }}
body: |
## Changelog
${{ steps.changelog.outputs.changelog }}
files: |
Samurais_Scripts_${{ steps.increment_tag.outputs.version_number }}.zip