|
1 | 1 | --- |
2 | | -name: release |
3 | | -run-name: release ${{ inputs.tag }} |
| 2 | +name: Release |
| 3 | +run-name: Release ${{ github.event.inputs.tag || '0.0.0-test' }} |
4 | 4 |
|
5 | 5 | on: |
6 | | - # Uncomment to test your work as a release before it's merged |
7 | | - # push: |
8 | | - # branches: |
9 | | - # - improvement/CLDSRVCLT-X |
| 6 | + # For testing - remove before merging |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - improvement/CLDSRVCLT-7 |
10 | 10 | workflow_dispatch: |
11 | 11 | inputs: |
12 | 12 | tag: |
13 | 13 | description: 'Tag to be released (e.g., 1.0.0)' |
14 | 14 | required: true |
15 | 15 |
|
| 16 | +env: |
| 17 | + # Use input tag for workflow_dispatch, or test tag for push events |
| 18 | + RELEASE_TAG: ${{ github.event.inputs.tag || '0.0.0-test' }} |
| 19 | + |
16 | 20 | jobs: |
17 | | - build-and-tag: |
18 | | - name: Build and tag |
| 21 | + check: |
| 22 | + name: Preliminary checks |
19 | 23 | runs-on: ubuntu-latest |
20 | | - permissions: |
21 | | - contents: write |
22 | | - |
| 24 | + # Only run check for manual workflow_dispatch (not for push events) |
| 25 | + if: github.event_name == 'workflow_dispatch' |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Ensure version matches tag |
| 31 | + run: | |
| 32 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 33 | + if [ "$PACKAGE_VERSION" != "${{ env.RELEASE_TAG }}" ]; then |
| 34 | + echo "::error file=package.json::Version $PACKAGE_VERSION doesn't match tag ${{ env.RELEASE_TAG }}" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +
|
| 38 | + build: |
| 39 | + name: Build and test |
| 40 | + runs-on: ubuntu-latest |
| 41 | + # For workflow_dispatch: wait for check. For push: run immediately |
| 42 | + needs: check |
| 43 | + if: always() && (needs.check.result == 'success' || needs.check.result == 'skipped') |
23 | 44 | steps: |
24 | 45 | - name: Checkout code |
25 | 46 | uses: actions/checkout@v4 |
26 | 47 |
|
27 | 48 | - name: Setup and Build |
28 | 49 | uses: ./.github/actions/setup-and-build |
29 | 50 |
|
30 | | - - name: Create Tag with Build Artifacts |
31 | | - run: | |
32 | | - # Configure git user to the GitHub Actions bot |
33 | | - git config --global user.name "github-actions[bot]" |
34 | | - git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | + - name: Run tests |
| 52 | + run: yarn test |
35 | 53 |
|
36 | | - # Force add the build folders (even if they are in .gitignore) |
37 | | - git add -f dist build |
| 54 | + - name: Upload build artifacts |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: build-artifacts |
| 58 | + path: | |
| 59 | + dist/ |
| 60 | + build/ |
38 | 61 |
|
39 | | - # Determine tag name |
40 | | - TAG_NAME="${{ inputs.tag }}" |
41 | | - if [ -z "$TAG_NAME" ]; then |
42 | | - TAG_NAME="test-${{ github.sha }}" |
43 | | - fi |
| 62 | + publish-npm: |
| 63 | + name: Publish to npm registry |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: build |
| 66 | + permissions: |
| 67 | + contents: read |
| 68 | + steps: |
| 69 | + - name: Checkout code |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Download build artifacts |
| 73 | + uses: actions/download-artifact@v4 |
| 74 | + with: |
| 75 | + name: build-artifacts |
44 | 76 |
|
45 | | - # Commit the build artifacts |
46 | | - git commit -m "Build artifacts for version $TAG_NAME" |
| 77 | + - name: Setup Node.js for npm registry |
| 78 | + uses: actions/setup-node@v4 |
| 79 | + with: |
| 80 | + node-version: '20' |
| 81 | + registry-url: 'https://registry.npmjs.org' |
47 | 82 |
|
48 | | - # Create the tag |
49 | | - git tag $TAG_NAME |
| 83 | + - name: Publish to npm |
| 84 | + run: npm publish |
| 85 | + env: |
| 86 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
50 | 87 |
|
51 | | - # Push the tag to the repository |
52 | | - git push origin $TAG_NAME |
| 88 | + create-release: |
| 89 | + name: Create GitHub Release |
| 90 | + runs-on: ubuntu-latest |
| 91 | + needs: publish-npm |
| 92 | + # Only create GitHub release for manual workflow_dispatch (not test pushes) |
| 93 | + if: github.event_name == 'workflow_dispatch' |
| 94 | + permissions: |
| 95 | + contents: write |
| 96 | + steps: |
| 97 | + - name: Checkout code |
| 98 | + uses: actions/checkout@v4 |
53 | 99 |
|
54 | | - # Export tag name for next step |
55 | | - echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT |
56 | | - id: create_tag |
| 100 | + - name: Create Git Tag |
| 101 | + run: | |
| 102 | + git config --global user.name "github-actions[bot]" |
| 103 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 104 | + git tag ${{ env.RELEASE_TAG }} |
| 105 | + git push origin ${{ env.RELEASE_TAG }} |
57 | 106 |
|
58 | 107 | - name: Create GitHub Release |
59 | 108 | uses: softprops/action-gh-release@v2 |
60 | 109 | with: |
61 | | - tag_name: ${{ steps.create_tag.outputs.tag_name }} |
62 | | - name: Release ${{ steps.create_tag.outputs.tag_name }} |
63 | | - draft: false |
64 | | - prerelease: false |
| 110 | + tag_name: ${{ env.RELEASE_TAG }} |
| 111 | + name: Release ${{ env.RELEASE_TAG }} |
| 112 | + generate_release_notes: true |
65 | 113 | env: |
66 | 114 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments