Merge pull request #31 from restfulhead/main #13
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 | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
issues: write | |
pull-requests: write | |
on: | |
push: | |
branches: | |
- release | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ inputs.git-ref }} | |
- name: Setup GIT | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "$GITHUB_ACTOR" | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: "npm" | |
cache-dependency-path: "package-lock.json" | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
env: | |
CI: true | |
run: | | |
npm ci | |
- name: Get workspaces | |
id: get-workspaces | |
run: | | |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
echo "commit=${{ github.sha }}" >> $GITHUB_OUTPUT | |
ws=$(npm ls --omit=dev --depth 1 -json | jq -r '.dependencies[].resolved[11:]') | |
echo 'ws<<EOF' >> $GITHUB_OUTPUT | |
echo $ws >> $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
- name: Build workspaces | |
env: | |
CI: true | |
run: | | |
npm run build -ws | |
- name: Release workspaces | |
if: steps.get-workspaces.outputs.ws != '' | |
env: | |
CI: true | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
topdir=$(pwd) | |
for workspace in ${{ steps.get-workspaces.outputs.ws }}; do | |
echo "Potentially going to version and release $workspace" | |
cd $workspace | |
mkdir .git | |
PCKG_NAME=`node -pe "require('./package.json').name"` | |
CUR_VERSION_NO=`node -pe "require('./package.json').version"` | |
FROM_PARAM="" | |
if [ "$CUR_VERSION_NO" != "0.0.0" ]; then | |
TAG_NAME="${PCKG_NAME}_v${CUR_VERSION_NO}" | |
REMOTE_TAGS=`git ls-remote --tags "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY"` | |
if echo "$REMOTE_TAGS" | grep -q "refs/tags/${TAG_NAME}"; then | |
echo "Identified previous release as ${TAG_NAME}." | |
FROM_PARAM="--from $TAG_NAME" | |
else | |
echo "::warning title=No previous tag found under ${TAG_NAME}:: This release will be based on the current branch." | |
fi | |
fi | |
DEBUG_FLAG= | |
if [ "${{ runner.debug}}" == "1" ]; then | |
DEBUG_FLAG="-vv" | |
fi | |
VERSION=`npx auto version $FROM_PARAM $DEBUG_FLAG` | |
if [ ! -z "$VERSION" ]; then | |
echo "::notice title=✅ Detected $VERSION version change for $PCKG_NAME::Bumping $VERSION version of $PCKG_NAME" | |
npx auto changelog --base-branch ${{ steps.get-workspaces.outputs.branch }} $FROM_PARAM $DEBUG_FLAG | |
npm run build | |
echo "npm version $VERSION -m 'chore: bump release version to %s [skip ci]'" | |
npm version $VERSION --tag-version-prefix="${PCKG_NAME}_v" -m "chore: bump release version to %s [skip ci]" | |
NEW_VERSION_NO=`node -pe "require('./package.json').version"` | |
NEW_TAG=${PCKG_NAME}_v$NEW_VERSION_NO | |
git add -A | |
git commit -m "chore: release $NEW_TAG [skip ci]" | |
git push "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags | |
npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }} $DEBUG_FLAG | |
IS_PRIVATE=`node -pe "require('./package.json').private"` | |
if [ "$IS_PRIVATE" != "true" ]; then | |
npm publish ./dist | |
echo "::notice title=🚀 ${PCKG_NAME} v$NEW_VERSION_NO::Package ${PCKG_NAME} v$NEW_VERSION_NO versioned and published" | |
fi | |
rm -rf .git | |
else | |
echo "::notice title=Versioning of $PCKG_NAME skipped::No relevant changes detected for $PCKG_NAME." | |
fi | |
cd $topdir | |
done | |
- if: ${{ always() }} | |
name: Clean working directory | |
run: | | |
rm -r * |