Skip to content

Commit

Permalink
v3.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DoneDeal0 committed Aug 21, 2024
1 parent fd57132 commit bce9d47
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
Expand All @@ -41,43 +41,58 @@ jobs:
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
needs: build
runs-on: ubuntu-latest
# create a current_version variable that can be used in the next steps
outputs:
current_version: ${{ steps.version_check.outputs.current_version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

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

- name: Install dependencies
run: npm install

- name: Build Talkr
run: npm run build
# fetch the latest release tag and compare it to the current package.json version
# publish if the version has been bumped
# if there is no tag (first release), the previous version is set to "none" and the publish step continues
- name: Check if package version has been bumped
id: version_check
run: |
current_version=$(jq -r '.version' package.json)
echo "current_version=$current_version" >> $GITHUB_ENV
git fetch --tags
previous_version=$(git tag --sort=-v:refname | head -n 1 || echo "none")
echo "previous_version=$previous_version" >> $GITHUB_ENV
if [ "$previous_version" != "none" ] && [ "$previous_version" == "v$current_version" ]; then
echo "Version has not been bumped. Exiting."
exit 1
fi
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const { execSync } = require('child_process');
// Read the current version from package.json
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const currentVersion = packageJson.version;
console.log(`Current version: ${currentVersion}`);
// Fetch the latest tags
execSync('git fetch --tags');
// Get the latest tag
let allTags = execSync('git tag -l --sort=v:refname').toString().trim().split('\n')
console.log(`all tags: ${allTags}`);
let previousVersion = allTags[0];
if (!previousVersion) {
previousVersion = 'none';
} else {
previousVersion = previousVersion.replace(/^v/, ''); // Remove the 'v' prefix if present
}
console.log(`Previous version: ${previousVersion}`);
// Check if the version has been bumped
if (previousVersion === currentVersion || currentVersion === '') {
console.log('Version has not been bumped. Exiting.');
process.exit(1);
}
// Set the current version as output
return { current_version: currentVersion };
- name: Publish to npm
if: ${{ steps.version_check.outputs.current_version != '' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access=public
Expand Down

0 comments on commit bce9d47

Please sign in to comment.