diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ce848a9..96a3df4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,117 +1,117 @@ name: Build and release package on: - push: - branches: - - main + push: + branches: + - main jobs: - tag: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - - name: Bump version and push tag - id: tag - uses: anothrNick/github-tag-action@1.67.0 - env: - WITH_V: false - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DEFAULT_BUMP: none - RELEASE_BRANCHES: main - - outputs: - bump: ${{ steps.tag.outputs.part }} - new_tag: ${{ steps.tag.outputs.new_tag }} - - build_release: - runs-on: ubuntu-latest - needs: tag - if: needs.tag.outputs.bump - permissions: - contents: write - steps: - - uses: pnpm/action-setup@v2 - with: - version: 8 - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Install JQ - run: sudo apt-get install -y jq - - - name: Bump package.json version - run: | - VERSION="${{ needs.tag.outputs.new_tag }}" - jq ".version=\"${VERSION}\"" ./package.json > ./package.tmp.json --tab - mv ./package.tmp.json ./package.json - - - name: Create npmrc file - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc - - - name: Install Node - uses: actions/setup-node@v3 - with: - node-version: "20" - cache: "pnpm" - - run: pnpm i --frozen-lockfile - - - name: Build artefacts - run: npm run build - - - name: Run tests - run: npm run test - - - name: Process changelog - id: changelog_file - run: | - if [[ ! -z $(cat changelog/next.md) ]] ; then - echo "changelog=v${{ needs.tag.outputs.new_tag }}" >> $GITHUB_OUTPUT - mv changelog/next.md changelog/v${{ needs.tag.outputs.new_tag }}.md - touch changelog/next.md - else - echo "changelog=next" >> $GITHUB_OUTPUT - fi - - - name: Commit changes to package.json version and changelog folder - continue-on-error: true - run: | - git config --global user.email "github@evomark.co.uk" - git config --global user.name "Evo Action" - git add . - git commit -m "Github Action updated version" - git push - - - name: Create NPM package - run: npm pack - - - name: Release to NPM - run: npm publish - - - name: Create Github release - id: create_release - uses: softprops/action-gh-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ needs.tag.outputs.new_tag }} - name: Release ${{ needs.tag.outputs.new_tag }} - body_path: changelog/${{ steps.changelog_file.outputs.changelog }}.md - draft: false - prerelease: false - - - name: Add NPM package to release - id: upload_release_asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./vue3-auto-vite-components-${{ needs.tag.outputs.new_tag }}.tgz - asset_name: vue3-auto-vite-components-${{ needs.tag.outputs.new_tag }}.tgz - asset_content_type: application/gzip + tag: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: "0" + + - name: Bump version and push tag + id: tag + uses: anothrNick/github-tag-action@1.67.0 + env: + WITH_V: false + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DEFAULT_BUMP: none + RELEASE_BRANCHES: main + + outputs: + bump: ${{ steps.tag.outputs.part }} + new_tag: ${{ steps.tag.outputs.new_tag }} + + build_release: + runs-on: ubuntu-latest + needs: tag + if: needs.tag.outputs.bump + permissions: + contents: write + steps: + - uses: pnpm/action-setup@v2 + with: + version: 8 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install JQ + run: sudo apt-get install -y jq + + - name: Bump package.json version + run: | + VERSION="${{ needs.tag.outputs.new_tag }}" + jq ".version=\"${VERSION}\"" ./package.json > ./package.tmp.json --tab + mv ./package.tmp.json ./package.json + + - name: Create npmrc file + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc + + - name: Install Node + uses: actions/setup-node@v3 + with: + node-version: "20" + cache: "pnpm" + - run: pnpm i + + - name: Build artefacts + run: npm run build + + - name: Run tests + run: npm run test + + - name: Process changelog + id: changelog_file + run: | + if [[ ! -z $(cat changelog/next.md) ]] ; then + echo "changelog=v${{ needs.tag.outputs.new_tag }}" >> $GITHUB_OUTPUT + mv changelog/next.md changelog/v${{ needs.tag.outputs.new_tag }}.md + touch changelog/next.md + else + echo "changelog=next" >> $GITHUB_OUTPUT + fi + + - name: Commit changes to package.json version and changelog folder + continue-on-error: true + run: | + git config --global user.email "github@evomark.co.uk" + git config --global user.name "Evo Action" + git add . + git commit -m "Github Action updated version" + git push + + - name: Create NPM package + run: npm pack + + - name: Release to NPM + run: npm publish + + - name: Create Github release + id: create_release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ needs.tag.outputs.new_tag }} + name: Release ${{ needs.tag.outputs.new_tag }} + body_path: changelog/${{ steps.changelog_file.outputs.changelog }}.md + draft: false + prerelease: false + + - name: Add NPM package to release + id: upload_release_asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./vue3-auto-vite-components-${{ needs.tag.outputs.new_tag }}.tgz + asset_name: vue3-auto-vite-components-${{ needs.tag.outputs.new_tag }}.tgz + asset_content_type: application/gzip