Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
release_tag:
description: 'Release tag to test (e.g., 1.2.3)'
required: true
release_description:
description: 'Release description for Update Center (e.g., "Support new feature")'
required: true
Comment thread
vdiez marked this conversation as resolved.
prerelease:
description: 'Mark as prerelease (publishes to npm "next" tag instead of "latest")'
type: boolean
Expand All @@ -33,6 +36,33 @@ jobs:
ARTIFACTORY_REPOSITORY_NAME: 'sonarsource-npm-public-releases'
DRY_RUN: ${{ inputs.dry_run || false }}
steps:
- name: Validate release description
id: description
env:
RELEASE_BODY: ${{ github.event.release.body }}
INPUT_DESCRIPTION: ${{ inputs.release_description }}
run: |
# Use input description for manual trigger, otherwise extract from release body
if [ -n "$INPUT_DESCRIPTION" ]; then
DESCRIPTION="$INPUT_DESCRIPTION"
else
# Extract description from release body (line starting with "Description:")
DESCRIPTION=$(echo "$RELEASE_BODY" | grep -i "^Description:" | sed 's/^[Dd]escription:[[:space:]]*//')
Comment thread
vdiez marked this conversation as resolved.
fi

if [ -z "$DESCRIPTION" ]; then
echo "::error::Release body must contain a 'Description:' line for the Update Center entry."
echo "::error::Example format:"
echo "::error:: Description: Support new authentication method"
echo "::error::"
echo "::error:: ## What's Changed"
echo "::error:: * PR details..."
exit 1
fi

echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
echo "Extracted description: $DESCRIPTION"

- name: Fetch the secrets
if: ${{ !inputs.dry_run }}
id: secrets
Expand Down Expand Up @@ -113,3 +143,86 @@ jobs:
# Publish as sonarqube-scanner (legacy alias for backwards compatibility)
echo $(jq '.name = "sonarqube-scanner"' package.json) > package.json
npm publish --tag=${{ steps.npm-tag.outputs.tag }} --access=public

outputs:
description: ${{ steps.description.outputs.description }}

update-center:
needs: publish
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release_tag }}
steps:
- name: Fetch GitHub token
id: secrets
uses: SonarSource/vault-action-wrapper@v3
with:
secrets: development/github/token/SonarSource-sonar-scanner-npm-update-center token | github_token;

- name: Checkout sonar-update-center-properties
uses: actions/checkout@v6
with:
repository: SonarSource/sonar-update-center-properties
token: ${{ fromJSON(steps.secrets.outputs.vault).github_token }}
path: update-center

- name: Update scannernpm.properties
working-directory: update-center
env:
RELEASE_DESCRIPTION: ${{ needs.publish.outputs.description }}
run: |
FILE="scannernpm.properties"
VERSION="${RELEASE_TAG}"
DATE=$(date +%Y-%m-%d)

# Get current publicVersions
CURRENT_PUBLIC=$(grep "^publicVersions=" "$FILE" | cut -d= -f2)

# Get current archivedVersions
CURRENT_ARCHIVED=$(grep "^archivedVersions=" "$FILE" | cut -d= -f2)

# Update archivedVersions: append current public versions
if [ -n "$CURRENT_ARCHIVED" ]; then
NEW_ARCHIVED="${CURRENT_ARCHIVED},${CURRENT_PUBLIC}"
else
NEW_ARCHIVED="${CURRENT_PUBLIC}"
fi

# Update the file
sed -i "s/^archivedVersions=.*/archivedVersions=${NEW_ARCHIVED}/" "$FILE"
sed -i "s/^publicVersions=.*/publicVersions=${VERSION}/" "$FILE"

# Find the line number of publicVersions and insert new version entry after it
LINE_NUM=$(grep -n "^publicVersions=" "$FILE" | cut -d: -f1)

# Create the new version entry and insert it
NEW_ENTRY="${VERSION}.description=${RELEASE_DESCRIPTION}
${VERSION}.date=${DATE}
${VERSION}.changelogUrl=https://github.com/SonarSource/sonar-scanner-npm/releases/tag/${VERSION}
${VERSION}.downloadUrl=https://www.npmjs.com/package/@sonar/scan/v/${VERSION}"

# Use awk to insert after the publicVersions line
awk -v line="$LINE_NUM" -v entry="$NEW_ENTRY" 'NR==line {print; print ""; print entry; next} 1' "$FILE" > tmp && mv tmp "$FILE"
Comment thread
vdiez marked this conversation as resolved.
Outdated

- name: Create Pull Request
working-directory: update-center
env:
GH_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).github_token }}
run: |
BRANCH="scannernpm-${RELEASE_TAG}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add scannernpm.properties
git commit -m "Update SonarScanner for NPM to ${RELEASE_TAG}"
git push origin "$BRANCH"
gh pr create \
--title "Update SonarScanner for NPM to ${RELEASE_TAG}" \
--body "Automated PR to update SonarScanner for NPM to version ${RELEASE_TAG}.

Created by [sonar-scanner-npm release workflow](https://github.com/SonarSource/sonar-scanner-npm/actions/runs/${{ github.run_id }})." \
Comment thread
vdiez marked this conversation as resolved.
--base master \
--reviewer SonarSource/quality-web-squad
Comment thread
vdiez marked this conversation as resolved.
Outdated
44 changes: 26 additions & 18 deletions docs/DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,23 @@ Releases are handled by the GitHub Actions workflow (`.github/workflows/release.

1. Create a new release on GitHub
2. Set the tag name (e.g., `1.2.3`)
3. The workflow will:
3. Add a `Description:` line in the release body (required for the Update Center)
4. The workflow will:
- Build the package with the release version
- Publish to Artifactory
- Publish to npm under two package names:
- `@sonar/scan` (primary)
- `sonarqube-scanner` (legacy alias for backwards compatibility)
- Create a PR in [sonar-update-center-properties](https://github.com/SonarSource/sonar-update-center-properties)

Example release body:

```
Description: Support new authentication method

## What's Changed
* SCANNPM-XXX Add new auth support by @user in #123
```

### npm Tags

Expand Down Expand Up @@ -86,33 +97,30 @@ You can test the release workflow without actually publishing by using the manua
3. Fill in the inputs:
- **Dry run**: ✅ checked (skips all publish steps)
- **Release tag**: The version to simulate (e.g., `1.2.3`)
- **Release description**: The description for the Update Center entry
- **Simulate prerelease**: Check to test prerelease behavior
- **Simulate [skip-latest]**: Check to test the skip-latest behavior

The workflow will run and display the npm tag that would be used without performing any actual build or publish operations.
The workflow will run and display the npm tag that would be used without performing any actual build or publish operations. The Update Center PR is still created during dry runs so you can verify the changes (just close the PR afterwards).

### Sonar Update Center

After publishing a new release, the [Sonar Update Center](https://xtranet-sonarsource.atlassian.net/wiki/spaces/DOC/pages/3385294896/The+Sonar+Update+Center) needs to be updated. This makes release information available at `downloads.sonarsource.com` for documentation and tooling.

#### Update Process
The [Sonar Update Center](https://xtranet-sonarsource.atlassian.net/wiki/spaces/DOC/pages/3385294896/The+Sonar+Update+Center) is automatically updated by the release workflow. When a release is published, the workflow creates a PR in [sonar-update-center-properties](https://github.com/SonarSource/sonar-update-center-properties) to update `scannernpm.properties` that:

1. **Create a PR** in [sonar-update-center-properties](https://github.com/SonarSource/sonar-update-center-properties) to update `scannernpm.properties`
- Adds the new version entry using the `Description:` from the release body
- Moves the previous public version to `archivedVersions`
- Requests review from `@SonarSource/quality-web-squad`

2. **Add the new version entry** with the following format:
#### Version Entry Format

```properties
X.Y.Z.description=Short description of the release
X.Y.Z.date=YYYY-MM-DD
X.Y.Z.changelogUrl=https://github.com/SonarSource/sonar-scanner-npm/releases/tag/X.Y.Z
X.Y.Z.downloadUrl=https://www.npmjs.com/package/@sonar/scan/v/X.Y.Z
```
Each version entry in `scannernpm.properties` follows this format:

3. **Update version lists**:
- Move the previous public version to `archivedVersions`
- Set the new version in `publicVersions`

4. **After PR is merged**, run the scanner release notes GitHub Action on the [SonarQube-Documentation](https://github.com/SonarSource/SonarQube-Documentation) repo to create a PR that pushes the update to product docs
```properties
X.Y.Z.description=Short description of the release
X.Y.Z.date=YYYY-MM-DD
X.Y.Z.changelogUrl=https://github.com/SonarSource/sonar-scanner-npm/releases/tag/X.Y.Z
X.Y.Z.downloadUrl=https://www.npmjs.com/package/@sonar/scan/v/X.Y.Z
```

#### Reference

Expand Down