From 0acd415b1294a1d5a1ab6ae53255f433930fe0e8 Mon Sep 17 00:00:00 2001 From: Jothi Priyadharshan Date: Tue, 27 Jul 2021 16:38:17 +0200 Subject: [PATCH] Create deploy.yml --- .github/workflows/deploy.yml | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..e6c3869 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,99 @@ +name: npm-publish +on: + push: + branches: + - master # Change this to your default branch +jobs: + npm-publish: + name: npm-publish + runs-on: ubuntu-latest + + steps: + # Publish to Node Package Manager + - name: Checkout Repo + uses: actions/checkout@main + + - name: Setup Node.js (NPM) + uses: actions/setup-node@master + with: + node-version: '12.x' + registry-url: 'https://registry.npmjs.org' + + - name: Use cached node_modules + uses: actions/cache@master + with: + path: node_modules + key: nodeModules-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + nodeModules- + + - name: Install dependencies + run: yarn install --frozen-lockfile + env: + CI: true + + - name: Update Publish Config + run: sed -i 's^registry-url^registry.npmjs.org^' package.json + + - name: Publish to NPM + run: npm publish --access public + env: + CI: true + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + + gpr-publish: + name: gpr-publish + runs-on: ubuntu-latest + + steps: + # Publish to GitHub Package Registry + - name: Checkout Repo + uses: actions/checkout@main + + - name: Store lowercase actor name + run: | + echo 'actor_name<> $GITHUB_ENV + echo ${{ github.actor }} | tr "A-Z" "a-z" >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Store package name + run: | + echo 'package_name<> $GITHUB_ENV + grep -Po '"name": *\K"[^"]*"' package.json | grep -oP '"\K[^"\047]+(?=["\047])' >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Setup Node.js (GPR) + uses: actions/setup-node@master + with: + node-version: '12.x' + registry-url: https://npm.pkg.github.com/ + scope: '${{ env.actor_name }}' + + - name: Use cached node_modules + uses: actions/cache@master + with: + path: node_modules + key: nodeModules-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + nodeModules- + + - name: Install dependencies + run: yarn install --frozen-lockfile + env: + CI: true + + - name: Update Package Name + run: | + sed -i 's,"name": "${{ env.package_name }}","name": "@${{ env.actor_name }}/${{ env.package_name }}",' package.json + cat package.json + + - name: Update Publish Config + run: | + sed -i 's^registry-url^npm.pkg.github.com/@${{ env.actor_name }}^' package.json + cat package.json + + - name: Publish to GitHub Package Registry + run: npm publish --access public + env: + CI: true + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}