Skip to content
Closed
Changes from all commits
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
53 changes: 46 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: 'Publish to NPM'

on:
# a pushed release tag v<version> publishes that version under 'latest'
push:
# javax tags (v<version>.javax) are not released by this workflow yet
tags: ['v*', '!v*.javax']
workflow_run:
workflows: ['CI (Client)']
types:
Expand Down Expand Up @@ -34,27 +38,63 @@ on:

permissions:
contents: read
actions: read
id-token: write

jobs:
publish:
name: Build & Publish
runs-on: ubuntu-22.04
if: github.repository == 'eclipse-glsp/glsp-eclipse-integration' && (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || (github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success'))
env:
DIST_TAG: ${{ github.event_name == 'push' && 'latest' || inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}
if: github.repository == 'eclipse-glsp/glsp-eclipse-integration' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || (github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success'))
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
ref: ${{ inputs.ref || github.event.inputs.ref || github.event.workflow_run.head_commit.id || github.sha }}
# Fetch all history to determine the canary version (commits since last tag)
fetch-depth: 0

- name: Check release tag
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
# a lightweight tag has no tag object and therefore no signature
run: |
# snapshots, release candidates and javax variants have no release path here
if [[ ! $GITHUB_REF_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Tag $GITHUB_REF_NAME is not a final release tag (v<major>.<minor>.<patch>)"
exit 1
fi
VERSION=$(node -p "require('./client/package.json').version")
if [[ "$GITHUB_REF_NAME" != "v$VERSION" ]]; then
echo "::error::Tag $GITHUB_REF_NAME does not match the version $VERSION in client/package.json"
exit 1
fi
TAG_SHA=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$GITHUB_REF_NAME" --jq 'select(.object.type == "tag") | .object.sha')
if [[ -z "$TAG_SHA" || $(gh api "repos/$GITHUB_REPOSITORY/git/tags/$TAG_SHA" --jq .verification.verified) != "true" ]]; then
echo "::error::Tag $GITHUB_REF_NAME is not a signed tag verified by GitHub"
exit 1
fi

- name: Check that CI passed on the tagged commit
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
run: |
CI=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow ci.yml --commit "$GITHUB_SHA" --event push --json conclusion --jq '.[0].conclusion')
[[ "$CI" == "success" ]] || { echo "::error::ci.yml has not passed on $GITHUB_SHA. Re-run this job once it has."; exit 1; }

- name: Check for changes in "client/packages" directory
id: check_changes
run: |
DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}"
# For 'next' dist-tag: check for changes when triggered by workflow_run or workflow_call
# For 'next' dist-tag: skip release versions, and check for changes when triggered by workflow_run or workflow_call
# For 'latest' dist-tag or workflow_dispatch: always publish
if [[ "$DIST_TAG" == "next" ]] && [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
if [[ "$DIST_TAG" == "next" && ! "$(node -p "require('./client/package.json').version")" =~ -next$ ]]; then
# a merged release PR puts a release version on master; releases publish from their tag
echo "::notice::Not on a next version. Skipping the next publish."
echo "should_publish=false" >> $GITHUB_OUTPUT
elif [[ "$DIST_TAG" == "next" ]] && [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
if git diff --name-only HEAD^ HEAD | grep -qE '^client/packages'; then
echo "should_publish=true" >> $GITHUB_OUTPUT
else
Expand Down Expand Up @@ -86,11 +126,10 @@ jobs:
if: steps.check_changes.outputs.should_publish == 'true'
working-directory: ./client
run: |
DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}"
if [[ "$DIST_TAG" == "next" ]]; then
pnpm publish:next
pnpm publish:next
elif [[ "$DIST_TAG" == "latest" ]]; then
pnpm publish:latest
pnpm publish:latest
else
echo "Unknown dist-tag: $DIST_TAG"
exit 1
Expand Down
Loading