Merge pull request #305 from ERC725Alliance/release-v0.18.0 #23
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
# If it detects a version bump on main, it will trigger a release. | |
# If the workflow is started manually, it will skip the bump detection and attempt to publish. | |
name: Release and publish | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
release: | |
name: π¦ Create GitHub release and publish to NPM | |
runs-on: ubuntu-latest | |
steps: | |
- name: Ensure main branch | |
if: github.ref != 'refs/heads/main' | |
run: |- | |
echo "Not running on main - exit" | |
exit 1 | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: π Check if version changed | |
uses: EndBug/version-check@v1 | |
if: github.event_name == 'push' | |
id: check | |
- name: π Check if should release | |
run: echo "SHOULD_RELEASE=${{ steps.check.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' }}" >> $GITHUB_ENV | |
- name: βοΈ Setup Node.js v16 | |
uses: actions/setup-node@v2 | |
if: env.SHOULD_RELEASE == 'true' | |
with: | |
node-version: '16.x' | |
registry-url: 'https://registry.npmjs.org' | |
scope: '@erc725' | |
cache: 'npm' | |
- name: π Set Version | |
if: env.SHOULD_RELEASE == 'true' | |
run: |- | |
APP_VERSION="v$(node -pe "require('./package.json').version")" | |
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV | |
- name: π§° Install | |
if: env.SHOULD_RELEASE == 'true' | |
run: npm ci | |
- name: π― Test | |
if: env.SHOULD_RELEASE == 'true' | |
run: npm test | |
- name: π Build | |
if: env.SHOULD_RELEASE == 'true' | |
run: npm run build | |
# We assume this will be always triggered by a merge from develop | |
# Therefore we tag the previous commit (the merge commit won't be on develop) | |
- name: π· Create and push Git Tag | |
if: env.SHOULD_RELEASE == 'true' | |
run: |- | |
git config --global user.email "release@lukso.network" | |
git config --global user.name "LUKSO Bot" | |
git tag -a ${{ env.APP_VERSION }} HEAD~ -m "Release Version ${{ env.APP_VERSION }} [CI]" | |
git push --set-upstream origin tag ${{ env.APP_VERSION }} | |
# Create GitHub Release | |
- name: π Extract release notes from CHANGELOG | |
if: env.SHOULD_RELEASE == 'true' | |
id: extract-release-notes | |
uses: ffurrer2/extract-release-notes@v1 | |
with: | |
release_notes_file: RELEASENOTES.md | |
- uses: jwalton/gh-find-current-pr@v1 | |
if: env.SHOULD_RELEASE == 'true' | |
id: findPR | |
with: | |
state: closed | |
- 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 | |
- name: π Create GitHub release | |
uses: ncipollo/release-action@v1 | |
if: env.SHOULD_RELEASE == 'true' | |
with: | |
bodyFile: 'RELEASENOTES.md' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ env.APP_VERSION }} | |
- name: π¦ Publish to NPM | |
if: env.SHOULD_RELEASE == 'true' | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |