Skip to content

chore: requirement node.js v20 as minimum #241

chore: requirement node.js v20 as minimum

chore: requirement node.js v20 as minimum #241

Workflow file for this run

name: Npm publish
on:
push:
branches:
- main
jobs:
check-files:
runs-on: ubuntu-latest
name: Check files changed
outputs:
changed-files: ${{ toJSON(steps.changed-files-docs.outputs) }}
bump-version: ${{ steps.changed-files-docs.outputs.only_changed == 'false' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files in the docs folder
id: changed-files-docs
env:
MONITORED_PATH: 'website'
run: |
# If pull request, compare the base and head
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
else
# For push event, compare the before and after
BASE_SHA=${{ github.event.before }}
HEAD_SHA=${{ github.event.after }}
# Handle the empty case (like first run or force push)
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
# If it's the first run, use the parent commit of the last commit
BASE_SHA=$(git rev-parse HEAD^)
HEAD_SHA=$(git rev-parse HEAD)
fi
fi
echo "Comparing $BASE_SHA...$HEAD_SHA"
# Get the changed files list - detect monitored path changes
MONITORED_CHANGES=$(git diff --name-status $BASE_SHA $HEAD_SHA | grep -E "^[ACDMRT]\s+${MONITORED_PATH}/" || true)
TOTAL_MONITORED_CHANGES=$(echo "$MONITORED_CHANGES" | grep -v "^$" | wc -l)
# Get all changed files for reference
ALL_CHANGES=$(git diff --name-only $BASE_SHA $HEAD_SHA)
TOTAL_CHANGES=$(echo "$ALL_CHANGES" | grep -v "^$" | wc -l)
# Extract the list of changed files
CHANGED_FILES=$(echo "$MONITORED_CHANGES" | awk '{print $2}')
# Create arrays for changed files
declare -a ALL_FILES_ARRAY
for file in $CHANGED_FILES; do
if [ ! -z "$file" ]; then
ALL_FILES_ARRAY+=("$file")
fi
done
# Convert to JSON using jq
ALL_FILES_JSON=$(printf "%s\n" "${ALL_FILES_ARRAY[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
# Escape quotes for GitHub Actions output
ESCAPED_ALL_FILES=$(echo "$ALL_FILES_JSON" | sed 's/"/\\"/g')
# Determine if only monitored directory changed or other files changed too
if [ $TOTAL_MONITORED_CHANGES -eq 0 ]; then
# No monitored changes
ONLY_CHANGED="true"
elif [ $TOTAL_MONITORED_CHANGES -eq $TOTAL_CHANGES ]; then
# Only monitored files changed
ONLY_CHANGED="true"
else
# Both monitored and other files changed
ONLY_CHANGED="false"
fi
# Debug output
echo "Monitored path: ${MONITORED_PATH}"
echo "Monitored changes: $TOTAL_MONITORED_CHANGES"
echo "Total changes: $TOTAL_CHANGES"
echo "Only monitored changed: $ONLY_CHANGED"
echo "Changed files: $ESCAPED_ALL_FILES"
# Set all outputs to match changed-files format
echo "all_changed_files=$ESCAPED_ALL_FILES" >> $GITHUB_OUTPUT
echo "all_changed_files_count=${#ALL_FILES_ARRAY[@]}" >> $GITHUB_OUTPUT
echo "only_changed=$ONLY_CHANGED" >> $GITHUB_OUTPUT
echo "any_changed=$([[ ${#ALL_FILES_ARRAY[@]} -gt 0 ]] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
publish:
if: needs.check-files.outputs.bump-version == 'true'
runs-on: ubuntu-latest
needs:
- check-files
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_HUB_TOKEN }}
- uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- run: npm add -g @antfu/ni
- run: nci
- name: Publish to npm
run: |
npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}"
pnpm -r --filter "./plugins/*" --filter "./packages/create-app" exec npm publish --access public --no-git-checks
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
- name: Config Git
run: |
git config --local user.name "bot"
git config --local user.email "bot@arcblock.io"
- name: Git Tag
run: |
git tag -a v${{ steps.package-version.outputs.current-version }} -m "chore(release): v${{ steps.package-version.outputs.current-version }}"
git push origin v${{ steps.package-version.outputs.current-version }}
- run: npx conventional-github-releaser -p angular
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{secrets.GITHUB_TOKEN}}