|
| 1 | +name: Deploy Styleguide |
| 2 | + |
| 3 | +concurrency: deploy |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - "src/**/*" |
| 11 | + - "package.json" |
| 12 | + - ".github/workflows/deploy.yml" |
| 13 | + - "tsconfig.json" |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + comment-id: |
| 17 | + description: "The comment-id of the slash command" |
| 18 | + required: true |
| 19 | + event-number: |
| 20 | + description: "The event-id of the slash command" |
| 21 | + required: true |
| 22 | + |
| 23 | +permissions: |
| 24 | + id-token: write |
| 25 | + contents: read |
| 26 | + |
| 27 | +jobs: |
| 28 | + deploy: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + persist-credentials: false |
| 34 | + ref: ${{ github.ref }} |
| 35 | + - uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: 20 |
| 38 | + registry-url: "https://registry.npmjs.org" |
| 39 | + - name: Cache pnpm modules |
| 40 | + uses: actions/cache@v4 |
| 41 | + with: |
| 42 | + path: ~/.pnpm-store |
| 43 | + key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}- |
| 46 | + - uses: pnpm/action-setup@v2.1.0 |
| 47 | + with: |
| 48 | + version: 9.0.6 |
| 49 | + run_install: true |
| 50 | + - name: Metadata |
| 51 | + id: metadata |
| 52 | + run: echo "::set-output name=commit::$(git rev-parse HEAD)" |
| 53 | + - name: Find Release Comment |
| 54 | + uses: peter-evans/find-comment@v3 |
| 55 | + id: find_comment |
| 56 | + if: ${{ github.ref != 'refs/heads/main' }} |
| 57 | + with: |
| 58 | + token: ${{ secrets.BOT_TOKEN }} |
| 59 | + issue-number: ${{ github.event.inputs.event-number }} |
| 60 | + comment-author: pythonitaliabot |
| 61 | + body-includes: "Pre-release" |
| 62 | + - name: Create or update comment |
| 63 | + id: initial-comment |
| 64 | + uses: peter-evans/create-or-update-comment@v4 |
| 65 | + if: ${{ github.ref != 'refs/heads/main' }} |
| 66 | + with: |
| 67 | + token: ${{ secrets.BOT_TOKEN }} |
| 68 | + comment-id: ${{ steps.find_comment.outputs.comment-id }} |
| 69 | + issue-number: ${{ github.event.inputs.event-number }} |
| 70 | + body: | |
| 71 | + # Pre-release |
| 72 | + :wave: |
| 73 | +
|
| 74 | + Releasing commit [${{ steps.metadata.outputs.commit }}] to NPM as pre-release! :package: |
| 75 | + edit-mode: replace |
| 76 | + - name: Update version |
| 77 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 78 | + run: pnpm version patch --no-git-tag-version |
| 79 | + - name: Update to pre-release version |
| 80 | + if: ${{ github.ref != 'refs/heads/main' }} |
| 81 | + run: | |
| 82 | + pnpm version patch --no-git-tag-version |
| 83 | + new_version=$(node -e "console.log(require('./package.json').version);") |
| 84 | + pnpm version $new_version-rc${{ steps.metadata.outputs.commit }} --no-git-tag-version |
| 85 | + - name: Build & Publish |
| 86 | + id: release |
| 87 | + run: | |
| 88 | + pnpm publish --tag ${{ fromJSON('["pr", "latest"]')[github.ref == 'refs/heads/main'] }} --no-git-checks |
| 89 | + new_version=$(node -e "console.log(require('./package.json').version);") |
| 90 | + echo "::set-output name=version::$new_version" |
| 91 | + - name: Commit version |
| 92 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 93 | + env: |
| 94 | + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} |
| 95 | + run: | |
| 96 | + new_version=$(node -e "console.log(require('./package.json').version);") |
| 97 | +
|
| 98 | + git remote set-url origin https://${{ secrets.BOT_TOKEN }}@github.com/${{ github.repository }} |
| 99 | + git config user.name "Python Italia [bot]" |
| 100 | + git config user.email "noreply@python.it" |
| 101 | + git add package.json |
| 102 | + git commit -m "🔨 Publish Styleguide v$new_version [skip ci]" |
| 103 | + git push |
| 104 | + - name: Create or update comment |
| 105 | + uses: peter-evans/create-or-update-comment@v3 |
| 106 | + if: ${{ github.ref != 'refs/heads/main' }} |
| 107 | + with: |
| 108 | + token: ${{ secrets.BOT_TOKEN }} |
| 109 | + comment-id: ${{ steps.initial-comment.outputs.comment-id }} |
| 110 | + issue-number: ${{ github.event.inputs.event-number }} |
| 111 | + body: | |
| 112 | + # Pre-release |
| 113 | + :wave: |
| 114 | +
|
| 115 | + Pre-release **${{ steps.release.outputs.version }}** [${{ steps.metadata.outputs.commit }}] has been released on NPM! :rocket: |
| 116 | + You can try it by doing: |
| 117 | + ```shell |
| 118 | + pnpm add @python-italia/pycon-styleguide@${{ steps.release.outputs.version }} |
| 119 | + ``` |
| 120 | + edit-mode: replace |
0 commit comments