ci: fix GitHub release step — add contents:write permission and creat… #8
This file contains hidden or 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 to npm | |
| on: | |
| push: | |
| branches: | |
| - production | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Type check (server) | |
| run: npm run test:ts:back | |
| - name: Type check (admin) | |
| run: npm run test:ts:front | |
| - name: Build | |
| run: npm run build | |
| - name: Verify plugin | |
| run: npm run verify | |
| - name: Check version not already published | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| if npm view strapi-plugin-form-builder-cms@$VERSION version 2>/dev/null; then | |
| echo "Version $VERSION is already published on npm." | |
| exit 1 | |
| fi | |
| echo "Version $VERSION is ready to publish." | |
| - name: Get package version | |
| id: pkg | |
| run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Set npm tag | |
| id: tag | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| if [[ "$VERSION" == *"alpha"* ]]; then | |
| echo "tag=alpha" >> $GITHUB_OUTPUT | |
| elif [[ "$VERSION" == *"beta"* ]]; then | |
| echo "tag=beta" >> $GITHUB_OUTPUT | |
| elif [[ "$VERSION" == *"rc"* ]]; then | |
| echo "tag=rc" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to npm | |
| run: npm publish --access public --tag ${{ steps.tag.outputs.tag }} | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create git tag | |
| run: | | |
| git tag v${{ steps.pkg.outputs.version }} | |
| git push origin v${{ steps.pkg.outputs.version }} | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.pkg.outputs.version }} | |
| name: v${{ steps.pkg.outputs.version }} | |
| generate_release_notes: true |