Skip to content

Commit

Permalink
👷‍♀️ Automatically release package
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgibson committed May 31, 2024
1 parent ca8d257 commit 7e7a212
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,29 @@ jobs:
run: npm run build
- name: Test
run: npm test

release:
needs:
- build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
- name: Install
# Skip post-install to avoid malicious scripts stealing PAT
run: npm install --ignore-script
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post-install
run: npm rebuild && npm run prepare --if-present
- name: Build
run: npm run build
- name: Release
run: ./deploy.sh
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 1 addition & 13 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VERSION="v$(node -p "require('./package.json').version")"
git checkout main
git pull
git fetch --tags

VERSION_COUNT=$(git tag --list $VERSION | wc -l)

if [ $VERSION_COUNT -gt 0 ]
Expand All @@ -15,20 +16,7 @@ else
echo "Deploying version $VERSION"
fi

echo '!/dist' >> .gitignore

npm install
npm test
npm run build

git checkout -b release-$VERSION
git add .gitignore
git add --all dist/
git commit --message "Release version $VERSION"
git tag $VERSION
git push origin refs/tags/$VERSION

npm publish

git checkout main
git branch --delete --force release-$VERSION

0 comments on commit 7e7a212

Please sign in to comment.