From 7e7a21202b05cf59656cf5abc5fa68d312945eca Mon Sep 17 00:00:00 2001 From: Alec Gibson <12036746+alecgibson@users.noreply.github.com> Date: Fri, 31 May 2024 09:35:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=E2=80=8D=E2=99=80=EF=B8=8F=20Autom?= =?UTF-8?q?atically=20release=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ deploy.sh | 14 +------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ec1b41..5e5f073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/deploy.sh b/deploy.sh index 17b67f0..fc71262 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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 ] @@ -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