Update version to 1.0.21 #61
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Version Check and Publish | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
packages: write | |
issues: write | |
env: | |
REPO_NAME: ${GITHUB_REPOSITORY#*/} | |
jobs: | |
check-version: | |
name: Check version | |
runs-on: ubuntu-latest | |
outputs: | |
should_update: ${{ steps.compare_versions.outputs.should_update }} | |
should_publish: ${{ steps.compare_versions.outputs.should_publish }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Compare versions and set output | |
id: compare_versions | |
run: | | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
NPM_VERSION=$(npm view ${{ env.REPO_NAME }} version) | |
HIGHEST_VERSION=$(echo -e "$CURRENT_VERSION\n$NPM_VERSION" | sort -V | tail -n 1) | |
if [ "$HIGHEST_VERSION" = "$NPM_VERSION" ]; then | |
echo "should_update=true" >> $GITHUB_OUTPUT | |
elif [ "$HIGHEST_VERSION" = "$CURRENT_VERSION" ]; then | |
echo "should_publish=true" >> $GITHUB_OUTPUT | |
fi | |
build: | |
name: Build | |
needs: check-version | |
if: needs.check-version.outputs.should_publish == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- name: Build | |
run: rm -rf dist && yarn build | |
- name: Prepare Template | |
run: | | |
cd dist | |
git clone https://github.com/Thre4dripper/NodeTs-Express-Service-Based-Template.git template | |
cd template | |
rm -rf .git && rm -rf .github | |
cd ../ | |
cp -r template template-ts && cp -r template template-js | |
cd template-ts && rm -rf src-javascript && mv src-typescript src | |
sed -i 's|"rootDir": "./src-typescript"|"rootDir": "./src"|g' tsconfig.json | |
cd ../ | |
cd template-js && rm -rf src-typescript && mv src-javascript src | |
rm tsconfig.json | |
cd ../ | |
rm -rf template | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build | |
path: | | |
./** | |
!node_modules/** | |
publish: | |
name: Publish to NPM | |
needs: build | |
if: needs.build.result == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: build | |
path: . | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Publish package on NPM | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
release: | |
name: Create Release | |
needs: publish | |
if: needs.publish.result == 'success' | |
runs-on: ubuntu-latest | |
outputs: | |
VERSION: ${{ steps.get_version.outputs.VERSION }} | |
steps: | |
- name: Get build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: build | |
path: . | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Get Version | |
id: get_version | |
run: | | |
VERSION=$(node -p "require('./package.json').version") | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
- name: Create Release | |
id: create_release | |
env: | |
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
tag: v${{ steps.get_version.outputs.VERSION }} | |
run: | | |
gh release create "$tag" \ | |
--repo="$GITHUB_REPOSITORY" \ | |
--title="Release $tag" \ | |
--generate-notes | |
- name: Create Release Asset | |
run: | | |
tar -czf release-v${{ steps.get_version.outputs.VERSION }}.tar.gz dist | |
shell: bash | |
- name: Upload Release Asset | |
run: | | |
gh release upload "$tag" release-v${{ steps.get_version.outputs.VERSION }}.tar.gz --clobber | |
shell: bash | |
update-version: | |
name: Update version | |
needs: check-version | |
if: needs.check-version.outputs.should_update == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.WORKFLOW_TOKEN }} | |
- name: Update version to next patch | |
run: | | |
git config --global user.name 'Version Bot' | |
git config --global user.email '[email protected]' | |
npm version patch -m "Update version to %s" | |
git push |