Repository navigation
fix: send push notifications as SSE events on the SSE transport #4679
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Flow PR Snapshot | |
| # Builds and publishes a Flow snapshot for a pull request, so that the change | |
| # can be tried out from a Maven repository before it is merged. The build is | |
| # opt-in per pull request: it runs once the "snapshot build" label is added and | |
| # then again for every commit pushed while the label is there. | |
| # | |
| # The version is derived from the branch name the same way the TeamCity feature | |
| # branch snapshot builds of the other Vaadin repositories derive theirs, so that | |
| # a Flow snapshot and, say, a Flow Components snapshot built from branches with | |
| # the same name resolve each other automatically. | |
| on: | |
| pull_request: | |
| types: [labeled, synchronize] | |
| # Deliberately unfiltered by base branch: a snapshot is as useful for a pull | |
| # request against a maintenance branch as for one against main. That branch | |
| # has to carry its own copy of this file for its pull requests, like | |
| # validation.yml. | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| concurrency: | |
| # One snapshot per pull request, superseded by the next push: only the newest | |
| # commit is worth publishing, and the version is the same for all of them. | |
| group: ${{ github.workflow }}-${{ github.event.number }} | |
| cancel-in-progress: true | |
| env: | |
| # Where the snapshot is uploaded, which is not the address below that it is | |
| # read from. A variable rather than a secret: masking it would buy nothing | |
| # and would only make the upload lines in the run log unreadable. Set per | |
| # repository, so a repository taking this workflow into use publishes | |
| # wherever it publishes - and then has to set the one below too, or the | |
| # comment will hand out an address its snapshot is not on. | |
| MAVEN_SNAPSHOT_DEPLOY_URL: ${{ vars.MAVEN_SNAPSHOT_DEPLOY_URL }} | |
| # Where the snapshot is read from afterwards, which is not the same address: | |
| # uploads go to the repository itself, resolving goes through the public one | |
| # in front of it. This is the one the pull request comment hands out, so it | |
| # has to stay public - a secret would only be masked in the run log anyway, | |
| # not in a comment. Overridable for a repository that publishes elsewhere. | |
| MAVEN_SNAPSHOT_READ_URL: ${{ vars.MAVEN_SNAPSHOT_READ_URL || 'https://maven.vaadin.com/vaadin-prereleases' }} | |
| _HEAD_REF: ${{ github.head_ref }} | |
| _HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| _PR_NUMBER: ${{ github.event.number }} | |
| jobs: | |
| snapshot: | |
| # A deploy needs the credentials, and secrets are only handed to pull | |
| # requests from a branch of this repository, never to a fork. Which is also | |
| # the access check: pushing that branch takes write access to the repository | |
| # and applying the label takes at least triage access, so a snapshot cannot | |
| # be triggered from the outside. Fork pull requests are skipped entirely - | |
| # labeling one does nothing. | |
| # | |
| # The label has to be present for both event types, and a `labeled` event | |
| # for some other label must not start a build of its own. | |
| # | |
| # Only in vaadin/flow: a copy of this repository that has the organization | |
| # secrets would otherwise deploy its own build to the shared snapshot | |
| # repository. | |
| if: >- | |
| github.repository == 'vaadin/flow' | |
| && !github.event.pull_request.head.repo.fork | |
| && contains(github.event.pull_request.labels.*.name, 'snapshot build') | |
| && (github.event.action != 'labeled' || github.event.label.name == 'snapshot build') | |
| timeout-minutes: 90 | |
| runs-on: ubuntu-26.04 | |
| steps: | |
| - name: Check configuration | |
| # The address is a variable and the credentials are secrets, but an | |
| # unset one of either ends the same way: an upload that fails after the | |
| # whole build, on something the step summary can say in a line here. | |
| env: | |
| SNAPSHOT_USERNAME: ${{ secrets.SNAPSHOT_USERNAME }} | |
| SNAPSHOT_PASSWORD: ${{ secrets.SNAPSHOT_PASSWORD }} | |
| run: | | |
| [ -z "$MAVEN_SNAPSHOT_DEPLOY_URL" ] || [ -z "$SNAPSHOT_USERNAME" ] || [ -z "$SNAPSHOT_PASSWORD" ] \ | |
| && echo "🚫 The **MAVEN_SNAPSHOT_DEPLOY_URL** variable or the **SNAPSHOT_USERNAME** / **SNAPSHOT_PASSWORD** secrets are not defined, check the configuration of **${{ github.repository }}**" \ | |
| | tee -a $GITHUB_STEP_SUMMARY && exit 1 || exit 0 | |
| - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 | |
| with: | |
| ref: ${{ env._HEAD_SHA }} | |
| - uses: ./.github/actions/setup-frontend-tools | |
| - name: Set up JDK | |
| uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 | |
| with: | |
| java-version-file: .tool-versions | |
| distribution: 'temurin' | |
| # Writes the settings.xml server entry the deploy below authenticates | |
| # with; the values are read from the environment at that point. | |
| server-id: vaadin-snapshots | |
| server-username: SNAPSHOT_USERNAME | |
| server-password: SNAPSHOT_PASSWORD | |
| - uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | |
| # Before the version rewrite below, so that the key is hashed from the | |
| # poms as committed and the prefix key reaches what validation.yml and | |
| # warm-caches.yml left behind. | |
| # | |
| # Read only on purpose, even though this build resolves a little more | |
| # than they do - the javadoc and deploy plugins, and the dependencies of | |
| # flow-gradle-plugin, which they leave out of their reactor - so that | |
| # much is downloaded again on every run. Saving it would mean an entry | |
| # of its own for every pull request, each a copy of a repository that | |
| # runs to gigabytes, against a repository wide cache quota shared with | |
| # the entries the test jobs actually need. A minute of downloads is the | |
| # cheaper side of that trade. | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-maven- | |
| - name: Compute the snapshot version | |
| id: version | |
| run: | | |
| # The default shell has -e but not pipefail, and the version below is | |
| # read through a pipe: without this a failed mvn would be a silent | |
| # empty string rather than a failed step. | |
| set -o pipefail | |
| # Everything up to the last slash is a prefix like feature/, fix/ or | |
| # issues/ and is dropped, leaving the branch name itself as the | |
| # qualifier: fix/my-thing -> 25.4.my-thing-SNAPSHOT. | |
| qualifier=$(printf '%s' "${_HEAD_REF##*/}" | sed -E 's/[^A-Za-z0-9.-]+/-/g; s/^[.-]+//; s/[.-]+$//') | |
| if [ -z "$qualifier" ]; then | |
| echo "🚫 Branch name \`$_HEAD_REF\` has no character a Maven version can carry" \ | |
| | tee -a $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi | |
| base=$(mvn -q -N -B -ntp org.apache.maven.plugins:maven-help-plugin:3.5.2:evaluate \ | |
| -Dexpression=project.version -DforceStdout | tail -1 | sed 's/-SNAPSHOT$//') | |
| # Anything else than a version means the lookup printed something | |
| # unexpected. Publishing what that composes into would be worse than | |
| # failing here: it deploys under a name nobody asked for. | |
| case "$base" in | |
| [0-9]*.[0-9]*) ;; | |
| *) | |
| echo "🚫 Read \`$base\` from the root pom instead of a version" \ | |
| | tee -a $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| ;; | |
| esac | |
| echo "version=$base.$qualifier-SNAPSHOT" >> $GITHUB_OUTPUT | |
| # The platform shares Flow's major and minor version, so the vaadin-bom | |
| # to pair the snapshot with is the snapshot of the branch it is built | |
| # on: 25.4.my-thing-SNAPSHOT goes with vaadin-bom 25.4-SNAPSHOT. | |
| echo "platform-version=$base-SNAPSHOT" >> $GITHUB_OUTPUT | |
| - name: Set the snapshot version | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| echo "Building $VERSION" | tee -a $GITHUB_STEP_SUMMARY | |
| ./scripts/computeMatrix.js set-version --version="$VERSION" | |
| - name: Build and deploy the snapshot | |
| id: deploy | |
| env: | |
| SNAPSHOT_USERNAME: ${{ secrets.SNAPSHOT_USERNAME }} | |
| SNAPSHOT_PASSWORD: ${{ secrets.SNAPSHOT_PASSWORD }} | |
| # -Drelease leaves the flow-tests modules out of the reactor: they are | |
| # never published (they set maven.deploy.skip) and building them would | |
| # roughly double this job. maven.javadoc.skip turns the javadoc jars | |
| # back on, so the snapshot carries the same artifacts a release does. | |
| # | |
| # flow-gradle-plugin stays in the reactor, unlike in validation.yml, | |
| # which leaves it out because its tests are a job of their own: on the | |
| # JDKs this workflow builds with, flow-plugins/pom.xml activates it, and | |
| # a snapshot should hold what a release holds. | |
| # | |
| # deployAtEnd holds every upload back until the whole reactor has built. | |
| # A push cancels the run in progress, and a cancel between two modules | |
| # would otherwise leave the version half published: the modules already | |
| # uploaded stay in the repository under the same version the next run | |
| # publishes, and if that run fails, whoever resolves the version gets a | |
| # mixed set of modules with nothing saying so. | |
| run: | | |
| if ! mvn deploy -B -ntp -e -DskipTests -Drelease -Dmaven.javadoc.skip=false \ | |
| -DdeployAtEnd=true \ | |
| -DaltDeploymentRepository="vaadin-snapshots::${MAVEN_SNAPSHOT_DEPLOY_URL}"; then | |
| # A refused upload arrives as a stack trace ending in an HTTP status, | |
| # a couple of hundred lines after the last thing that was built, and | |
| # says nothing about which of the three settings is wrong. It is the | |
| # failure to expect while a repository is being taken into use. | |
| echo "🚫 The snapshot build failed. A **401** or **403** at the end of the log means the build itself was fine and the upload was refused: a 401 is usually a wrong or expired **SNAPSHOT_PASSWORD**, a 403 means **SNAPSHOT_USERNAME** is not allowed to deploy there, and either can also be **MAVEN_SNAPSHOT_DEPLOY_URL** pointing at the address the repository is read from rather than its deploy endpoint." \ | |
| | tee -a $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi | |
| - name: Comment the snapshot version on the pull request | |
| # Runs after a failed deploy too. Otherwise the comment of an earlier | |
| # run keeps announcing a published version while the commit that was | |
| # meant to replace it never made it into the repository, with nothing | |
| # on the pull request saying so. Skipped on a cancel, where the run | |
| # that superseded this one is about to write the comment itself, and | |
| # when there is no version yet either, where the run failed before it | |
| # had anything to say about a snapshot. | |
| if: ${{ !cancelled() && steps.version.outputs.version != '' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ steps.version.outputs.version }} | |
| PLATFORM_VERSION: ${{ steps.version.outputs.platform-version }} | |
| DEPLOY_OUTCOME: ${{ steps.deploy.outcome }} | |
| run: | | |
| marker='<!-- flow-pr-snapshot -->' | |
| run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| # The heredocs are written at the indentation of this block rather | |
| # than of the branch they sit in, because their content is the | |
| # comment body verbatim, delimiter included. | |
| if [ "$DEPLOY_OUTCOME" = success ]; then | |
| cat > comment.md <<EOF | |
| $marker | |
| ### 📦 Snapshot published | |
| \`$VERSION\` — built from ${_HEAD_SHA:0:7} ([run]($run_url)). | |
| Built without running tests. Look at the checks on this pull request before relying on it. | |
| Every new commit on this branch republishes it while the \`snapshot build\` label is there. Add \`-U\` to pick the newest build up. | |
| <details><summary>How to use it</summary> | |
| EOF | |
| else | |
| cat > comment.md <<EOF | |
| $marker | |
| ### 🚫 Snapshot build failed | |
| \`$VERSION\` was not published: the build from ${_HEAD_SHA:0:7} failed ([run]($run_url)). Anything the repository already holds under that version is from an earlier commit of this branch. | |
| <details><summary>How to use that earlier build, if there is one</summary> | |
| EOF | |
| fi | |
| # The same coordinates either way, and worth keeping on a failure: | |
| # they are what reaches the build this one did not replace. | |
| cat >> comment.md <<EOF | |
| \`\`\`xml | |
| <repository> | |
| <id>vaadin-snapshots</id> | |
| <url>$MAVEN_SNAPSHOT_READ_URL</url> | |
| <snapshots><enabled>true</enabled></snapshots> | |
| </repository> | |
| <dependencyManagement> | |
| <dependencies> | |
| <dependency> | |
| <groupId>com.vaadin</groupId> | |
| <artifactId>flow-bom</artifactId> | |
| <version>$VERSION</version> | |
| <type>pom</type> | |
| <scope>import</scope> | |
| </dependency> | |
| <!-- After flow-bom, so that its Flow version wins --> | |
| <dependency> | |
| <groupId>com.vaadin</groupId> | |
| <artifactId>vaadin-bom</artifactId> | |
| <version>$PLATFORM_VERSION</version> | |
| <type>pom</type> | |
| <scope>import</scope> | |
| </dependency> | |
| </dependencies> | |
| </dependencyManagement> | |
| \`\`\` | |
| Replace the application's own \`vaadin-bom\` import with these two rather than adding them next to it: with two \`vaadin-bom\` imports, the first one decides the platform version. \`flow-bom\` has to come before \`vaadin-bom\`: Maven takes the first version it finds for an artifact, so the other order leaves the platform's own Flow version in use. \`$PLATFORM_VERSION\` is the unreleased platform snapshot of the same minor version as this one, so this also moves the application off its released platform version. | |
| </details> | |
| EOF | |
| # One comment per pull request, edited in place, so a series of pushes | |
| # does not bury the pull request in notifications. --jq runs once per | |
| # page under --paginate, so each page yields at most one id and the | |
| # first of those is the comment; two would make the PATCH a 404. The | |
| # trimming is a parameter expansion rather than a pipe, so a failed | |
| # listing still ends the step instead of reading as "none yet" and | |
| # posting a second comment. | |
| existing=$(gh api "repos/${{ github.repository }}/issues/$_PR_NUMBER/comments" --paginate \ | |
| --jq "[.[] | select(.body | startswith(\"$marker\")) | .id] | first // empty") | |
| existing=${existing%%$'\n'*} | |
| if [ -n "$existing" ]; then | |
| gh api --method PATCH "repos/${{ github.repository }}/issues/comments/$existing" -F body=@comment.md | |
| else | |
| gh api "repos/${{ github.repository }}/issues/$_PR_NUMBER/comments" -F body=@comment.md | |
| fi |