|
| 1 | +# yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json |
| 2 | +--- |
| 3 | +name: Publish |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_run: |
| 7 | + workflows: ["Integration Tests"] |
| 8 | + types: |
| 9 | + - completed |
| 10 | + branches: |
| 11 | + - main |
| 12 | + push: |
| 13 | + tags: |
| 14 | + - 'v*.*.*' |
| 15 | + - '*.*.*' |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + publish-ea: |
| 23 | + if: | |
| 24 | + github.event_name == 'workflow_run' && |
| 25 | + github.event.workflow_run.head_branch == 'main' |
| 26 | + runs-on: ubuntu-latest |
| 27 | + name: Publish EA release to NPM |
| 28 | + steps: |
| 29 | + - name: Checkout sources |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Install node 24 |
| 36 | + uses: actions/setup-node@v5 |
| 37 | + with: |
| 38 | + node-version: 24 |
| 39 | + cache: npm |
| 40 | + registry-url: 'https://registry.npmjs.org' |
| 41 | + |
| 42 | + - name: Update npm |
| 43 | + run: npm install -g npm@latest |
| 44 | + |
| 45 | + - name: Configure git |
| 46 | + run: | |
| 47 | + git config user.name "${{ github.actor }}" |
| 48 | + git config user.email "${{ github.actor }}@users.noreply.github.com" |
| 49 | +
|
| 50 | + - name: Get current version |
| 51 | + id: current-version |
| 52 | + run: | |
| 53 | + VERSION=$(node -p "require('./package.json').version") |
| 54 | + # Remove both -ea. and -ea- formats for compatibility |
| 55 | + BASE_VERSION=$(echo "$VERSION" | sed -E 's/-ea[.-][0-9]+$//') |
| 56 | + echo "base-version=$BASE_VERSION" >> "$GITHUB_OUTPUT" |
| 57 | + echo "current-version=$VERSION" >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Update package with EA version |
| 60 | + id: bump |
| 61 | + run: | |
| 62 | + EA_VERSION="${{ steps.current-version.outputs.base-version }}-ea-${{ github.run_number }}" |
| 63 | + npm version "$EA_VERSION" --no-git-tag-version |
| 64 | + echo "version=$EA_VERSION" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Install project modules |
| 67 | + run: npm ci |
| 68 | + |
| 69 | + - name: Compile project |
| 70 | + run: npm run compile |
| 71 | + |
| 72 | + - name: Publish package |
| 73 | + run: npm publish --verbose --tag ea --access public --provenance |
| 74 | + |
| 75 | + - name: Commit and push package modifications |
| 76 | + run: | |
| 77 | + git add package.json |
| 78 | + git add package-lock.json |
| 79 | + git commit -m "build: updated package with ${{ steps.bump.outputs.version }} [skip ci]" |
| 80 | + git push |
| 81 | +
|
| 82 | + - name: Create and push new tag |
| 83 | + run: | |
| 84 | + git tag ${{ steps.bump.outputs.version }} -m "${{ steps.bump.outputs.version }}" |
| 85 | + git push origin ${{ steps.bump.outputs.version }} |
| 86 | +
|
| 87 | + publish-release: |
| 88 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 89 | + runs-on: ubuntu-latest |
| 90 | + name: Publish release to NPM |
| 91 | + steps: |
| 92 | + - name: Checkout sources |
| 93 | + uses: actions/checkout@v4 |
| 94 | + with: |
| 95 | + ref: ${{ github.ref }} |
| 96 | + fetch-depth: 0 |
| 97 | + |
| 98 | + - name: Install node 24 |
| 99 | + uses: actions/setup-node@v5 |
| 100 | + with: |
| 101 | + node-version: 24 |
| 102 | + cache: npm |
| 103 | + registry-url: 'https://registry.npmjs.org' |
| 104 | + |
| 105 | + - name: Update npm |
| 106 | + run: npm install -g npm@latest |
| 107 | + |
| 108 | + - name: Get tag name |
| 109 | + id: tag |
| 110 | + run: | |
| 111 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 112 | + echo "name=$TAG_NAME" >> "$GITHUB_OUTPUT" |
| 113 | +
|
| 114 | + - name: Update package.json with tag version |
| 115 | + id: update-version |
| 116 | + run: | |
| 117 | + TAG_NAME="${{ steps.tag.outputs.name }}" |
| 118 | + # Remove 'v' prefix if present |
| 119 | + VERSION=${TAG_NAME#v} |
| 120 | + npm version "$VERSION" --no-git-tag-version |
| 121 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 122 | +
|
| 123 | + - name: Install project modules |
| 124 | + run: npm ci |
| 125 | + |
| 126 | + - name: Compile project |
| 127 | + run: npm run compile |
| 128 | + |
| 129 | + - name: Publish package |
| 130 | + run: npm publish --verbose --access public --provenance |
0 commit comments