Skip to content

Commit

Permalink
feat(workflows): test
Browse files Browse the repository at this point in the history
  • Loading branch information
buroa committed Jan 2, 2025
1 parent a63573a commit 34a6912
Showing 1 changed file with 45 additions and 31 deletions.
76 changes: 45 additions & 31 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,51 @@ jobs:
app-id: "${{ secrets.BOT_APP_ID }}"
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"

- name: Checkout
uses: actions/checkout@v4
- name: Get Previous Release Tag and Determine Next Tag
id: determine-next-tag
uses: actions/github-script@v7
with:
token: "${{ steps.app-token.outputs.token }}"
github-token: "${{ steps.app-token.outputs.token }}"
result-encoding: string
script: |
const { data: releases } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1,
});
let previousTag = "0.0.0"; // Default if no previous release exists
if (releases.length > 0) {
previousTag = releases[0].tag_name;
}
const [previousMajor, previousMinor, previousPatch] = previousTag.split('.').map(Number);
const currentYear = new Date().getFullYear();
const currentMonth = new Date().getMonth() + 1; // Months are 0-indexed in JavaScript
const nextMajorMinor = `${currentYear}.${currentMonth}`;
let nextPatch;
if (`${previousMajor}.${previousMinor}` === nextMajorMinor) {
console.log("Month release already exists for the year. Incrementing patch number by 1.");
nextPatch = previousPatch + 1;
} else {
console.log("Month release does not exist for the year. Starting with patch number 0.");
nextPatch = 0;
}
return `${nextMajorMinor}.${nextPatch}`;
- name: Create Release
env:
GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
run: |
# Retrieve previous release tag
previous_tag="$(gh release list --limit 1 --json tagName --jq '.[0].tagName')"
if [[ -z "${previous_tag}" ]]; then
echo "No previous release found. Starting with the first release of the year and month."
previous_tag="0.0.0"
fi
# Parse previous release tag into components
previous_major=$(cut -d. -f1 <<<"${previous_tag}")
previous_minor=$(cut -d. -f2 <<<"${previous_tag}")
previous_patch=$(cut -d. -f3 <<<"${previous_tag}")
# Determine next release tag components
next_major_minor="$(date +'%Y').$(date +'%-m')"
if [[ "${previous_major}.${previous_minor}" == "${next_major_minor}" ]]; then
echo "Month release already exists for year, incrementing patch number by 1"
next_patch="$((previous_patch + 1))"
else
echo "Month release does not exist for year, setting patch number to 0"
next_patch="0"
fi
# Create release
release_tag="${next_major_minor}.${next_patch}"
gh release create "${release_tag}" \
--repo="${GITHUB_REPOSITORY}" \
--title="${release_tag}" \
--generate-notes
uses: actions/github-script@v7
with:
github-token: "${{ steps.app-token.outputs.token }}"
script: |
const releaseTag = ${{ steps.determine-next-tag.outputs.result }};
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: releaseTag,
name: releaseTag,
generate_release_notes: true,
});

0 comments on commit 34a6912

Please sign in to comment.