|
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_repo: |
| 7 | + description: 'GLSP repository to publish' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - glsp |
| 12 | + - glsp-client |
| 13 | + - glsp-theia-integration |
| 14 | + - glsp-server |
| 15 | + - glsp-server-node |
| 16 | + - glsp-eclipse-integration |
| 17 | + - glsp-vscode-integration |
| 18 | + - glsp-playwright |
| 19 | + branch: |
| 20 | + description: 'Branch to use for the release repo (default: default branch)' |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + draft: |
| 24 | + description: 'Create draft GitHub release' |
| 25 | + required: false |
| 26 | + type: boolean |
| 27 | + default: false |
| 28 | + workflow_call: |
| 29 | + inputs: |
| 30 | + release_repo: |
| 31 | + description: 'GLSP repository to publish' |
| 32 | + required: true |
| 33 | + type: string |
| 34 | + branch: |
| 35 | + description: 'Branch to use for the release repo (default: default branch)' |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + draft: |
| 39 | + description: 'Create draft GitHub release' |
| 40 | + required: false |
| 41 | + type: boolean |
| 42 | + default: false |
| 43 | + |
| 44 | +jobs: |
| 45 | + publish: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + steps: |
| 48 | + - name: Checkout release repo (${{ inputs.release_repo || github.event.inputs.release_repo }}) |
| 49 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 50 | + with: |
| 51 | + repository: eclipse-glsp/${{ inputs.release_repo || github.event.inputs.release_repo }} |
| 52 | + path: release-repo |
| 53 | + ref: ${{ inputs.branch || github.event.inputs.branch }} |
| 54 | + fetch-depth: 0 |
| 55 | + |
| 56 | + - name: Configure Git |
| 57 | + run: | |
| 58 | + git config --global user.name "github-actions[bot]" |
| 59 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 60 | +
|
| 61 | + - name: Extract and validate version |
| 62 | + id: version |
| 63 | + working-directory: ./release-repo |
| 64 | + run: | |
| 65 | + # Extract version from package.json or pom.xml |
| 66 | + if [ -f package.json ]; then |
| 67 | + VERSION=$(jq -r '.version' package.json) |
| 68 | + elif [ -f pom.xml ]; then |
| 69 | + VERSION=$(grep -m1 '<version>' pom.xml | sed 's/.*<version>\(.*\)<\/version>.*/\1/') |
| 70 | + else |
| 71 | + echo "::error::No package.json or pom.xml found" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "Detected version: $VERSION" |
| 76 | +
|
| 77 | + # Validate: no pre-release versions (no '-' in version) |
| 78 | + if [[ "$VERSION" == *-* ]]; then |
| 79 | + echo "::error::Cannot publish pre-release version: $VERSION" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + # Validate: last commit message must contain the version tag |
| 84 | + LAST_COMMIT=$(git log -1 --pretty=%s) |
| 85 | + if [[ "$LAST_COMMIT" != *"v$VERSION"* ]]; then |
| 86 | + echo "::error::Last commit message does not contain v$VERSION: $LAST_COMMIT" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +
|
| 90 | + # Validate: CHANGELOG.md must have an entry for this version |
| 91 | + if ! grep -q "^## \[v$VERSION" CHANGELOG.md; then |
| 92 | + echo "::error::CHANGELOG.md has no entry for v$VERSION" |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | +
|
| 96 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 97 | +
|
| 98 | + - name: Extract changelog section |
| 99 | + id: changelog |
| 100 | + working-directory: ./release-repo |
| 101 | + run: | |
| 102 | + VERSION="${{ steps.version.outputs.version }}" |
| 103 | + REPO="${{ inputs.release_repo || github.event.inputs.release_repo }}" |
| 104 | +
|
| 105 | + # Extract section: skip the header line, grab until next ## [v heading |
| 106 | + CONTENT=$(awk -v ver="$VERSION" ' |
| 107 | + /^## \[v/ { |
| 108 | + if (found) exit |
| 109 | + if (index($0, "## [v" ver) == 1) { found=1; next } |
| 110 | + } |
| 111 | + found { print } |
| 112 | + ' CHANGELOG.md) |
| 113 | +
|
| 114 | + # Remove leading blank lines |
| 115 | + CONTENT=$(echo "$CONTENT" | sed '/./,$!d') |
| 116 | +
|
| 117 | + # Demote ### headings to ## |
| 118 | + CONTENT=$(echo "$CONTENT" | sed 's/^### /## /g') |
| 119 | +
|
| 120 | + # Append Full Changelog link if a previous release tag exists |
| 121 | + PREV_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^v${VERSION}$" | head -1) |
| 122 | + if [ -n "$PREV_TAG" ]; then |
| 123 | + CONTENT="$CONTENT |
| 124 | +
|
| 125 | + **Full Changelog**: https://github.com/eclipse-glsp/$REPO/compare/$PREV_TAG...v$VERSION" |
| 126 | + fi |
| 127 | +
|
| 128 | + # Write to file for gh release --notes-file |
| 129 | + echo "$CONTENT" > "$RUNNER_TEMP/changelog_section.md" |
| 130 | +
|
| 131 | + - name: Create and push git tag |
| 132 | + working-directory: ./release-repo |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + run: | |
| 136 | + VERSION="${{ steps.version.outputs.version }}" |
| 137 | + git tag -a "v$VERSION" -m "Release v$VERSION" |
| 138 | + git push origin tag "v$VERSION" |
| 139 | +
|
| 140 | + - name: Create GitHub release |
| 141 | + working-directory: ./release-repo |
| 142 | + env: |
| 143 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 144 | + run: | |
| 145 | + VERSION="${{ steps.version.outputs.version }}" |
| 146 | + REPO="${{ inputs.release_repo || github.event.inputs.release_repo }}" |
| 147 | + DRAFT_FLAG="" |
| 148 | + if [[ "${{ inputs.draft || github.event.inputs.draft }}" == "true" ]]; then |
| 149 | + DRAFT_FLAG="--draft" |
| 150 | + fi |
| 151 | +
|
| 152 | + gh release create "v$VERSION" \ |
| 153 | + --title "Release v$VERSION" \ |
| 154 | + --notes-file "$RUNNER_TEMP/changelog_section.md" \ |
| 155 | + --repo "eclipse-glsp/$REPO" \ |
| 156 | + $DRAFT_FLAG |
| 157 | +
|
| 158 | + - name: Trigger npm trusted publishing |
| 159 | + if: >- |
| 160 | + inputs.release_repo != 'glsp-server' && |
| 161 | + inputs.release_repo != 'glsp-eclipse-integration' && |
| 162 | + github.event.inputs.release_repo != 'glsp-server' && |
| 163 | + github.event.inputs.release_repo != 'glsp-eclipse-integration' |
| 164 | + env: |
| 165 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 166 | + run: | |
| 167 | + VERSION="${{ steps.version.outputs.version }}" |
| 168 | + REPO="${{ inputs.release_repo || github.event.inputs.release_repo }}" |
| 169 | +
|
| 170 | + gh workflow run publish.yml \ |
| 171 | + --repo "eclipse-glsp/$REPO" \ |
| 172 | + -f "ref=v$VERSION" \ |
| 173 | + -f "dist-tag=latest" |
0 commit comments