|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Triggers on version tags like v1.0.0, v2.1.3, etc. |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # Required for creating releases |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 # Fetch full history for changelog generation |
| 19 | + |
| 20 | + - name: Use Node.js # will read version from .nvmrc |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version-file: '.nvmrc' |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: npm ci |
| 27 | + |
| 28 | + - name: Run tests |
| 29 | + run: npm run test |
| 30 | + |
| 31 | + - name: Build |
| 32 | + run: npm run build |
| 33 | + |
| 34 | + - name: Extract version from tag |
| 35 | + id: version |
| 36 | + run: | |
| 37 | + # Remove 'v' prefix from tag to get version |
| 38 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 39 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 40 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Generate changelog for GitHub Release |
| 43 | + id: changelog |
| 44 | + run: | |
| 45 | + # Get the previous tag |
| 46 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 47 | +
|
| 48 | + # Generate changelog between tags |
| 49 | + if [ -n "$PREV_TAG" ]; then |
| 50 | + CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD) |
| 51 | + else |
| 52 | + CHANGELOG=$(git log --pretty=format:"- %s (%h)") |
| 53 | + fi |
| 54 | +
|
| 55 | + # Save changelog to output (handle multiline) |
| 56 | + echo "changelog<<EOF" >> $GITHUB_OUTPUT |
| 57 | + echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 58 | + echo "EOF" >> $GITHUB_OUTPUT |
| 59 | +
|
| 60 | + - name: Create GitHub Release |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + run: | |
| 64 | + # Create release body |
| 65 | + cat > release_body.md << 'EOF' |
| 66 | + ## Changes in ${{ steps.version.outputs.tag }} |
| 67 | +
|
| 68 | + ${{ steps.changelog.outputs.changelog }} |
| 69 | +
|
| 70 | + ## Installation |
| 71 | +
|
| 72 | + ```bash |
| 73 | + npm install @dynatrace-oss/dynatrace-mcp-server@${{ steps.version.outputs.version }} |
| 74 | + ``` |
| 75 | + EOF |
| 76 | +
|
| 77 | + # Create the release |
| 78 | + if [[ "${{ steps.version.outputs.version }}" == *"-"* ]]; then |
| 79 | + gh release create "${{ steps.version.outputs.tag }}" \ |
| 80 | + --title "Release ${{ steps.version.outputs.tag }}" \ |
| 81 | + --notes-file release_body.md \ |
| 82 | + --prerelease |
| 83 | + else |
| 84 | + gh release create "${{ steps.version.outputs.tag }}" \ |
| 85 | + --title "Release ${{ steps.version.outputs.tag }}" \ |
| 86 | + --notes-file release_body.md |
| 87 | + fi |
0 commit comments