Skip to content

NPM Dependency Reports #55

NPM Dependency Reports

NPM Dependency Reports #55

Workflow file for this run

name: Test
env:
CHANGELOG: '' # Leave empty.
on:
# Manually triggered
workflow_dispatch:
jobs:
create_github_release:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
# Get latest changes
- name: Get latest changes
run: git pull
# Get new version number
- name: Get the version from package.json
id: package_version
run: echo "VERSION=1.0.2" >> $GITHUB_OUTPUT
# Get previous official version
- name: Get previous official version
id: previous_version
run: |
PREV_VERSION=$(git tag --sort=-creatordate | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
echo "PREV_VERSION=$PREV_VERSION" >> $GITHUB_OUTPUT
# Tag the version
- name: Create GitHub Tag
run: |
git tag ${{ steps.package_version.outputs.VERSION }}
git push origin ${{ steps.package_version.outputs.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Install GitHub CLI for use in changelog step
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
# Install JQ for use in changelog step
- name: Install jq
run: |
sudo apt-get install -y jq
# Create changelog (only official releases)
- name: Create changelog
id: changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the current version from package.json
VERSION=${{ steps.package_version.outputs.VERSION }}
# Get the previous official version
PREV_VERSION=${{ steps.previous_version.outputs.PREV_VERSION }}
# Generate comparison link
if [ -n "$PREV_VERSION" ]; then
COMPARISON_URL="https://github.com/${{ github.repository }}/compare/$PREV_VERSION...$VERSION"
else
COMPARISON_URL=""
fi
# Generate technical documentation link
TECH_DOCS_URL="https://github.com/${{ github.repository }}/tree/$VERSION/techdocs/docs"
CHANGELOG=""
# Get the list of commits between the previous and current versions
COMMITS=$(git log 1.0.0-beta..HEAD --pretty=format:"%s %b")
# Extract pull request numbers from the commit messages
PR_NUMBERS=$(echo "$COMMITS" | grep -oE "#[0-9]+" | sort | uniq)
for PR_NUMBER in $PR_NUMBERS; do
# Get the pull request details
PR=$(gh pr view $PR_NUMBER --json title,url)
TITLE=$(echo "$PR" | jq -r '.title')
URL=$(echo "$PR" | jq -r '.url')
CHANGELOG="${CHANGELOG}\n- ${TITLE} (${URL})"
done
# Escape changelog content for GitHub Actions without encoding newlines
ESCAPED_CHANGELOG=$(echo "$CHANGELOG" | node -e "const escapeForGitHubActions = (str) => str.replace(/%/g, '%25').replace(/\\r/g, '%0D'); process.stdin.on('data', data => process.stdout.write(escapeForGitHubActions(data.toString())));")
# Set the CHANGELOG environment variable with the constructed changelog, comparison link, and technical documentation link
{
echo "CHANGELOG<<EOF"
echo "<details><summary>Pull Requests</summary>"
echo "$ESCAPED_CHANGELOG"
echo "</details>"
echo ""
[ -n "$COMPARISON_URL" ] && echo "[Compare changes since last version]($COMPARISON_URL)"
echo "[Documentation]($TECH_DOCS_URL)"
echo "EOF"
} >> $GITHUB_ENV
# Create new release in GitHub (only official releases)
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.package_version.outputs.VERSION }}
name: 'Test'
body: ${{ env.CHANGELOG }}