Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test

- name: Build
run: npm run build

- name: Check for uncommitted changes
run: |
if [ -n "$(git status --porcelain dist/)" ]; then
echo "Error: dist/ has uncommitted changes"
git diff dist/
exit 1
fi
95 changes: 2 additions & 93 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,99 +34,8 @@ outputs:
value: ${{ steps.generate.outputs.long-sha }}

runs:
using: "composite"
steps:
- name: Generate release tag and create release
id: generate
uses: actions/github-script@v8
with:
github-token: ${{ inputs.github-token }}
script: |
const { data: { commit, sha } } = await github.rest.repos.getCommit({
...context.repo,
ref: '${{ inputs.commit }}'
});

const commitDate = new Date(commit.committer.date);
const isoDate = commitDate.toISOString();

const pad = (n) => String(n).padStart(2, '0');
const year = commitDate.getUTCFullYear();
const month = commitDate.getUTCMonth() + 1;
const day = commitDate.getUTCDate();
const hour = commitDate.getUTCHours();
const minute = commitDate.getUTCMinutes();
const second = commitDate.getUTCSeconds();

const tokens = [
['{YYYY}', year],
['{YY}', String(year).slice(-2)],
['{MM}', pad(month)],
['{M}', month],
['{DD}', pad(day)],
['{D}', day],
['{HH}', pad(hour)],
['{H}', hour],
['{mm}', pad(minute)],
['{m}', minute],
['{ss}', pad(second)],
['{s}', second]
];

let tag = '${{ inputs.tag-format }}';
tag = tag.replace(/\{sha:(\d+)\}/g, (_, len) => {
return sha.substring(0, parseInt(len));
});
tag = tag.replace(/\{sha\}/g, sha);
for (const [token, value] of tokens) {
tag = tag.replaceAll(token, value);
}

try {
await github.rest.repos.getReleaseByTag({
...context.repo,
tag: tag
});
core.setFailed(
`Release with tag '${tag}' already exists.\n` +
`This means the commit has already been released.`
);
return;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}

const releaseName = '${{ inputs.release-name }}'.replaceAll('{tag}', tag);

let releaseNotes = (await github.rest.repos.generateReleaseNotes({
...context.repo,
tag_name: tag,
target_commitish: '${{ inputs.commit }}'
})).data.body || '';

// Need to truncate otherwise createRelease fails.
const maxLength = 124900;
if (releaseNotes.length > maxLength) {
releaseNotes = releaseNotes.substring(0, maxLength) +
'\n\n... (truncated)';
}

await github.rest.repos.createRelease({
...context.repo,
tag_name: tag,
name: releaseName,
body: releaseNotes
});

const shortSha = sha.substring(0, 7);
core.setOutput('tag', tag);
core.setOutput('iso-date', isoDate);
core.setOutput('short-sha', shortSha);
core.setOutput('long-sha', sha);

core.info(`Created release '${releaseName}' with tag '${tag}'`);
using: "node20"
main: "dist/index.js"

branding:
icon: "tag"
Expand Down
Loading