Skip to content

Merge pull request #266 from ERC725Alliance/develop #47

Merge pull request #266 from ERC725Alliance/develop

Merge pull request #266 from ERC725Alliance/develop #47

Workflow file for this run

# This workflow create a new git tag and release
# a new version of the @erc725/smart-contracts package
# on npm: https://www.npmjs.com/package/@erc725/smart-contracts
name: NPM Release
on:
workflow_dispatch:
push:
branches:
- "main"
jobs:
release:
name: 📦 Create GitHub release and publish to NPM
runs-on: ubuntu-latest
defaults:
run:
working-directory: implementations
steps:
- name: Ensure main branch
if: github.ref != 'refs/heads/main'
run: |-
echo "Not running on main - exit"
exit 1
# step 1: checkout to the correct branch
- uses: actions/checkout@v4
with:
fetch-depth: 0
# step 2: setup Node.js to version 16
- name: Setup Node.js v20
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
cache: "npm"
cache-dependency-path: implementations/package-lock.json
# all these steps should only happen if
# - the version in package.json has increased
# - we are pushing to main
- name: 🔍 Check if version in package.json has changed
uses: EndBug/version-check@v1
if: github.event_name == 'push'
id: PACKAGE_VERSION_INCREASED
with:
diff-search: true
file-name: ./implementations/package.json
- name: 🔄 Check if should release
run: echo "SHOULD_RELEASE=${{ steps.PACKAGE_VERSION_INCREASED.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' }}" >> $GITHUB_ENV
- name: 📝 Set version
if: env.SHOULD_RELEASE == 'true'
run: |
PACKAGE_VERSION="v$(node -pe "require('./package.json').version")"
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
# step 3: install npm dependencies
- name: 🧰 Install dependencies
if: env.SHOULD_RELEASE == 'true'
run: npm ci
# Step 4: compile + test the contracts.
- name: 🛠 Build
if: env.SHOULD_RELEASE == 'true'
run: npm run build --if-present
- name: 🧪 Test
if: env.SHOULD_RELEASE == 'true'
run: npm run test
# step 5: create a new release on Github
# 5.1) create + push a git tag
- name: 🏷 Create and push Git Tag
if: env.SHOULD_RELEASE == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "LUKSO bot"
git tag -a ${{ env.PACKAGE_VERSION }} HEAD~ -m "Release Version ${{ env.PACKAGE_VERSION }} [CI]"
git push --set-upstream origin tag ${{ env.PACKAGE_VERSION }}
# 5.2) extract release note information
- name: 📝 Extract release notes from CHANGELOG
if: env.SHOULD_RELEASE == 'true'
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v1
with:
changelog_file: implementations/CHANGELOG.md
release_notes_file: implementations/RELEASENOTES.md
- name: Add PR body to Release Notes
if: env.SHOULD_RELEASE == 'true'
env:
PR_BODY: ${{ steps.findPR.outputs.body }}
run: |
echo ${PR_BODY} | cat - RELEASENOTES.md > /tmp/out && mv /tmp/out RELEASENOTES.md
# 5.3) create the new release
- name: 🚀 Create Github release
if: env.SHOULD_RELEASE == 'true'
uses: ncipollo/release-action@v1
with:
bodyFile: "implementations/RELEASENOTES.md"
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.PACKAGE_VERSION }}
# step 6: publish to NPM
- name: 📦 Publish to NPM
if: env.SHOULD_RELEASE == 'true'
run: |
npm run package
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}