Update package.json. #57
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: Release | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
#on: | |
# workflow_call: | |
# inputs: | |
# tag: | |
# required: true | |
# type: string | |
jobs: | |
release: | |
runs-on: ubuntu-22.04 | |
name: Release an Updated Version | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
- name: Install Dependencies | |
run: npm install | |
- name: Compile | |
run: | | |
npm i -g @vercel/ncc | |
ncc build index.js --license licenses.txt | |
- name: Configure git | |
run : | | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Compose Release Tag | |
id: tags | |
run: | | |
TIMESTAMP=$(git show -s --format=%at $SHA) | |
DEV_TAG=dev-$TIMESTAMP | |
BASE_RELEASE_TAG="v0." | |
REPO=$(echo "$GITHUB_CONTEXT" | jq -r '.repository') | |
LATEST_RELEASE=$(jq -r '.[0] | .tag_name' <<< $(curl --silent https://api.github.com/repos/$REPO/releases)) | |
if [ -n "$LATEST_RELEASE" ]; then | |
# if latest release tag is v0.1, this extracts the `1` from it then increments it. | |
VER="${LATEST_RELEASE#*.}" | |
VER=$((VER + 1)) | |
else | |
VER="1" | |
fi | |
RELEASE_TAG=v0.$VER | |
echo "SHA: $SHA" | |
echo "DEV_TAG: $DEV_TAG" | |
echo "RELEASE_TAG: $RELEASE_TAG" | |
echo "SHA=$SHA" >> $GITHUB_OUTPUT | |
echo "DEV_TAG=$DEV_TAG" >> $GITHUB_OUTPUT | |
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT | |
- name: Commit compiled version | |
id: commit | |
run: | | |
if [ ${{ github.ref }} == "refs/heads/dev" ]; then | |
BRANCH="dev-nightly-release" | |
else | |
BRANCH="main" | |
fi | |
git switch -C $BRANCH | |
git add --force dist/* | |
git commit -m "Add compiled js file [Invoker ${{ steps.tags.outputs.SHA }}]." | |
echo "BRANCH=$BRANCH" >> $GITHUB_OUTPUT | |
- name: Publish Dev Tag | |
if: github.ref == 'refs/heads/dev' | |
run: | | |
BRANCH=${{ steps.commit.outputs.BRANCH }} | |
git tag -a -m ${{ steps.tags.outputs.DEV_TAG }} ${{ steps.tags.outputs.DEV_TAG }} | |
git push --set-upstream origin $BRANCH --force --follow-tags | |
- name: Release | |
if: github.ref == 'refs/heads/main' | |
id: release | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
TAG=${{ steps.tags.outputs.RELEASE_TAG }} | |
REPO=$(echo "$GITHUB_CONTEXT" | jq -r '.repository') | |
# gh api repos/$REPO/git/refs -f ref="refs/tags/$TAG" -f sha="$SHA" | |
gh release create $TAG --repo "$REPO" --title "Release $TAG" --generate-notes | |
# TAG=${{ steps.release_tag.outputs.TAG }} | |
# SHA= | |
# | |
# # git tag -a ${{ steps.release_tag.outputs.TAG }} | |
# # git push --follow-tags | |
# | |