Refactor publish workflow to clone repository, initialize submodules,… #10
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
name: Publish npm package | |
on: push | |
env: | |
NPM_TOKEN: ${{secrets.GH_PRIVATE_NPM_TOKEN}} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Checkout source code" | |
uses: actions/checkout@v3 | |
- name: "Setup node" | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.x | |
- name: "Check build" | |
run: npm install | |
bump-version: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: "Checkout source code" | |
uses: actions/checkout@v3 | |
- name: "cat package.json (before bump)" | |
run: cat ./package.json | |
- name: "Automated Version Bump" | |
id: version-bump | |
uses: "phips28/gh-action-bump-version@master" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "cat package.json (after bump)" | |
run: cat ./package.json | |
- name: "Output New Version" | |
env: | |
NEW_TAG: ${{ steps.version-bump.outputs.newTag }} | |
run: echo "new tag $NEW_TAG" | |
- name: "Upload modified files" | |
uses: actions/upload-artifact@v3 | |
with: | |
name: modified-files | |
path: | | |
./package.json | |
./package-lock.json | |
publish-gpr: | |
needs: bump-version | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Checkout source code" | |
uses: actions/checkout@v3 | |
# Clone the repository to a temporary directory | |
- name: "Clone repository to temp directory" | |
run: git clone ${{ github.event.repository.clone_url }} temp-repo | |
# Initialize and update submodules | |
- name: "Initialize submodules" | |
run: | | |
cd temp-repo | |
git submodule update --init --recursive | |
- name: "Download modified files" | |
uses: actions/download-artifact@v3 | |
with: | |
name: modified-files | |
- name: "Setup node" | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.x | |
- name: "Install can-npm-publish" | |
run: | | |
cd temp-repo | |
npm install can-npm-publish --save-dev | |
- name: Setup .temp-npmrc file to authenticate with npm | |
run: | | |
cd temp-repo | |
echo "//registry.npmjs.org/:_authToken=${{ env.NPM_TOKEN }}" > .temp-npmrc | |
- name: "Git status check" | |
run: | | |
cd temp-repo | |
git status | |
- name: "Publish package if needed" | |
run: | | |
cd temp-repo | |
npx can-npm-publish --verbose && npm publish --no-git-checks --userconfig .temp-npmrc || echo "Does not publish" |