Skip to content

Merge pull request #44 from oasysgames/fix/add_dir_for_testing #39

Merge pull request #44 from oasysgames/fix/add_dir_for_testing

Merge pull request #44 from oasysgames/fix/add_dir_for_testing #39

Workflow file for this run

name: Release Workflow
on:
push:
branches:
- main
tags:
- "v0.2.x"
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
- name: Install type definitions
run: npm install --save-dev @types/node @types/fs-extra
- name: Compile TypeScript
run: npx tsc
- name: Lint with eslint
run: npm run lint
- name: Run tests
run: npm run test
prepare-release:
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.set_git_tag.outputs.target_tag_name }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set target major and minor version
run: |
echo "target_major_minor_tag=v0.2.x" >> $GITHUB_ENV
- name: Get latest tag
id: getlatesttag
run: |
git fetch --prune --unshallow
echo "$(git tag --sort=creatordate | tail -n 1)" > CUR_TAG
echo "cur_tag=$(cat CUR_TAG)" >> $GITHUB_ENV
- name: Set release tag
id: set_release_tag
run: |
# Assuming target_major_minor_tag has a format like "vX.Y.x"
# Extract major and minor version from the target_major_minor_tag
TARGET_MAJOR=$(echo $target_major_minor_tag | cut -d. -f1)
TARGET_MINOR=$(echo $target_major_minor_tag | cut -d. -f2)
# Extract major, minor, and patch from the current tag
MAJOR=$(echo $cur_tag | cut -d. -f1)
MINOR=$(echo $cur_tag | cut -d. -f2)
PATCH=$(echo $cur_tag | cut -d. -f3)
# If the major and minor versions of the current tag match the target versions, then start the patch version from 0.
if [[ "$MAJOR" == "$TARGET_MAJOR" && "$MINOR" == "$TARGET_MINOR" ]]; then
NEW_TAG="${TARGET_MAJOR}.${TARGET_MINOR}.0"
else
# Otherwise, increment the patch version
NEW_TAG="${MAJOR}.${MINOR}.$((PATCH+1))"
fi
# Export the new tag for subsequent steps
echo "tag_name=$NEW_TAG" >> $GITHUB_ENV
- name: Use computed tag
run: |
echo "Next tag will be: ${{ env.tag_name }}"
- name: Push the new tag
id: set_git_tag
run: |
echo "${{ env.tag_name }}" > TARGET_TAG_NAME
cat TARGET_TAG_NAME
git tag $(cat TARGET_TAG_NAME)
git push origin $(cat TARGET_TAG_NAME)
echo "::set-output name=target_tag_name::${{ env.tag_name }}"
- name: Create release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.target_tag_name }}
release_name: Release ${{ env.target_tag_name }}
draft: true
prerelease: false
build-and-release:
needs: prepare-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build with pkg
run: |
npm i
npx tsc
npm install -g pkg
pkg . -t node18-linux-x64 --output ./oasys-csv-cli-linux
pkg . -t node18-macos-x64 --output ./oasys-csv-cli-macos
pkg . -t node18-win-x64 --output ./oasys-csv-cli-win.exe
- name: Create GitHub Release and Upload binaries/source
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.prepare-release.outputs.new_tag }}
files: |
./oasys-csv-cli-linux,
./oasys-csv-cli-macos,
./oasys-csv-cli-win.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}