Skip to content

chore(tsoa-deno): Rename tsoa to tsoa-deno #112

chore(tsoa-deno): Rename tsoa to tsoa-deno

chore(tsoa-deno): Rename tsoa to tsoa-deno #112

name: Publish Deno runtime package
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
check_if_version_upgraded:
name: Check if packages/runtime version has been upgraded
runs-on: ubuntu-latest # or another runner
outputs:
from_version: ${{ steps.version_check.outputs.from_version }}
to_version: ${{ steps.version_check.outputs.to_version }}
is_upgraded_version: ${{ steps.version_check.outputs.is_upgraded_version }}
is_pre_release: ${{ steps.version_check.outputs.is_pre_release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Check Version
id: version_check
uses: actions/github-script@v7
with:
script: |
const path = require('path');
const fs = require('fs');
// Get runtime package.json path
const packagePath = path.join(process.env.GITHUB_WORKSPACE, 'packages/runtime/package.json');
// Function to read package version
const readVersion = (filePath) => {
const packageContent = JSON.parse(fs.readFileSync(filePath));
return packageContent.version;
};
// Get current version
const currentVersion = readVersion(packagePath);
const getLatestRelease = async () => {
const response = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
console.log("Release response", response.data.map(entry => entry.tag_name));
// Assuming the first release in the list is the latest
return response.data[0]?.tag_name.replace("v","") || "";
};
// Get previous version
const previousVersion = await getLatestRelease();
// Check if version is upgraded
const isUpgraded = currentVersion !== previousVersion;
const isPreRelease = currentVersion.includes('-');
const outputs = {
from_version: previousVersion,
to_version: currentVersion,
is_upgraded_version: isUpgraded.toString(),
is_pre_release: isPreRelease.toString()
};
core.setOutput("from_version", previousVersion);
core.setOutput("to_version", currentVersion);
core.setOutput("is_upgraded_version", isUpgraded.toString());
core.setOutput("is_pre_release", isPreRelease.toString());
console.log("outputs", outputs);
return outputs;
publish:
runs-on: ubuntu-latest
needs:
- check_if_version_upgraded
# We create a release only if the version have been upgraded and we are on the main branch
# or if we are on a branch of the repo that has an PR open on main.
if: |
needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' &&
(
github.event_name == 'push' ||
needs.check_if_version_upgraded.outputs.is_pre_release == 'true'
)
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
- run: rm -r .github
- name: Remove tmp_branch if it exists
run: git push origin :tmp_branch || true
- run: git checkout -b tmp_branch
- uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
- uses: bahmutov/npm-install@v1
- run: yarn build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
npm run build:deno
env:
DRY_RUN: "0"
- run: |
git config --global user.name "actions"
git config --global user.email actions@github.com
sed -i '/packages\/runtime\/deno_dist/d' .gitignore
cp packages/runtime/README.deno.md packages/runtime/deno_dist/README.md
git add -A
git commit -am "Add TSOA runtime Deno distribution files"
git push origin tmp_branch
- uses: softprops/action-gh-release@v1
with:
name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }}
tag_name: v${{ needs.check_if_version_upgraded.outputs.to_version }}
target_commitish: tmp_branch
generate_release_notes: false
draft: false
prerelease: ${{ needs.check_if_version_upgraded.outputs.is_pre_release == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove tmp_branch
run: git push origin :tmp_branch