CD #80
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: CD | |
on: | |
workflow_run: | |
workflows: ['CI'] | |
types: | |
- completed | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.conclusion == 'success' && | |
github.event.workflow_run.head_branch == 'main' | |
steps: | |
- name: Checkout and pnpm | |
uses: actions/[email protected] | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Setup Node.js | |
uses: actions/[email protected] | |
with: | |
node-version: '20.x' | |
cache: pnpm | |
cache-dependency-path: './pnpm-lock.yaml' | |
- name: Install Dependencies | |
run: pnpm i | |
- name: Build | |
run: pnpm freshBuild | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Configure npm for GitHub Packages | |
run: | | |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc | |
echo "@wojtekkrol:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
- name: Insert repository owner as scope into package name | |
run: | | |
cp package.json package.json.bak | |
node <<EOF | |
const fs = require('fs').promises; | |
fs.readFile('package.json', 'utf8').then((data) => JSON.parse(data)).then((json) => { | |
json.name = '@' + process.env.GITHUB_REPOSITORY.split('/')[0].toLowerCase() + '/' + json.name; | |
console.info('Package name changed to %s', json.name); | |
return fs.writeFile('package.json', JSON.stringify(json, null, 2), 'utf8'); | |
}).catch(error => { | |
console.error(error); | |
process.exit(1); | |
}); | |
EOF | |
env: | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
- name: Insert repository owner as scope into package name | |
run: | | |
cp package.json package.json.bak | |
node <<EOF | |
const fs = require('fs').promises; | |
fs.readFile('package.json', 'utf8').then((data) => JSON.parse(data)).then((json) => { | |
json.name = '@' + process.env.GITHUB_REPOSITORY.split('/')[0] + '/' + json.name; | |
console.info('Package name changed to %s', json.name); | |
return fs.writeFile('package.json', JSON.stringify(json, null, 2), 'utf8'); | |
}).catch(error => { | |
console.error(error); | |
process.exit(1); | |
}); | |
EOF | |
env: | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
- name: Publish to GitHub Packages | |
run: pnpm publish --registry=https://npm.pkg.github.com/ --no-git-checks | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Revert package.json | |
run: mv package.json.bak package.json | |
- name: Publish to npm | |
run: pnpm publish:npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |