Skip to content
Open
Show file tree
Hide file tree
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
91 changes: 87 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ name: Publish packages on NPM
on:
release:
types: [released]
workflow_dispatch: {} # Allow for manual trigger.
workflow_dispatch:
inputs:
channel:
description: 'Publish channel (latest or dev)'
required: true
default: 'dev'
type: choice
options:
- latest
- dev
version:
description: 'Version to publish (leave empty to use current version in package.json)'
required: false
type: string

jobs:
publish:
Expand All @@ -17,17 +30,86 @@ jobs:
node-version: '24'
registry-url: 'https://registry.npmjs.org'

- name: Validate and set channel
id: channel
run: |
# Defaults to 'latest' for release events, otherwise uses dispatch input (which defaults to 'dev').
CHANNEL="${{ github.event.inputs.channel || 'latest' }}"
BRANCH="${{ github.ref_name }}"

# Restrict 'latest' channel to master branch only
if [ "$CHANNEL" = "latest" ] && [ "$BRANCH" != "master" ]; then
echo "Error: The 'latest' channel can only be published from the 'master' branch."
echo "Current branch: $BRANCH"
echo "Use the 'dev' channel for publishing from other branches."
exit 1
fi

echo "channel=$CHANNEL" >> $GITHUB_OUTPUT
echo "Publishing to channel: $CHANNEL from branch: $BRANCH"

- name: Validate and set version
id: version
run: |
VERSION="${{ github.event.inputs.version }}"
CHANNEL="${{ steps.channel.outputs.channel }}"
BRANCH="${{ github.ref_name }}"

# If version is provided, validate it
if [ -n "$VERSION" ]; then
echo "Using provided version: $VERSION"

# Restrict version override on master branch to non-latest channels only
if [ "$BRANCH" = "master" ] && [ "$CHANNEL" = "latest" ]; then
echo "Error: Cannot provide a custom version when publishing to 'latest' channel from the 'master' branch."
echo "For 'latest' channel on master, the version from package.json must be used."
exit 1
fi

# For dev channel, verify version ends with -dev.<number>
if [ "$CHANNEL" = "dev" ]; then
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-dev\.[0-9]+$'; then
echo "Error: Dev channel versions must end with -dev.<number> (e.g., 1.0.0-dev.0)"
exit 1
fi
fi

echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "has_version=true" >> $GITHUB_OUTPUT
else
echo "No version provided, will use current package.json version"
echo "has_version=false" >> $GITHUB_OUTPUT
fi

- run: yarn

- name: Set version if provided
if: steps.version.outputs.has_version == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Setting version to: $VERSION"
yarn version:all "$VERSION"
- run: yarn workspace @datadog/rollup-plugin buildBasic
- run: export BUILD_PLUGINS_ENV=production
- run: yarn publish:all

- name: Publish to NPM
run: |
CHANNEL="${{ steps.channel.outputs.channel }}"
if [ "$CHANNEL" = "dev" ]; then
echo "Publishing to dev channel with --tag dev"
yarn loop --no-private npm publish --tag dev
else
echo "Publishing to latest channel"
yarn loop --no-private npm publish
fi
env:
ADD_BUILD_PLUGINS: 1
DD_GITHUB_JOB_NAME: Publish to NPM # Needs to be the same as the job to have CI Vis link the spans.
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
- name: Log version published
run: |
VERSION="$(yarn workspace @datadog/webpack-plugin info @datadog/webpack-plugin --json | jq -r '.children.Version')"
CHANNEL="${{ steps.channel.outputs.channel }}"
HEADERS=(
-H "Content-Type: application/json"
-H "X-Datadog-Origin: build-plugins"
Expand All @@ -36,11 +118,12 @@ jobs:
DATA="{
\"ddsource\": \"github\",
\"service\": \"build-plugins\",
\"message\": \"Latest version published: $VERSION\",
\"message\": \"Version published to $CHANNEL channel: $VERSION\",
\"status\": \"success\",
\"env\": \"production\",
\"team\": \"language-foundations\",
\"version\": \"$VERSION\"
\"version\": \"$VERSION\",
\"channel\": \"$CHANNEL\"
}"
URL="https://http-intake.logs.datadoghq.com/api/v2/logs"
curl -X POST "${HEADERS[@]}" -d "$DATA" "$URL"
Expand Down
65 changes: 40 additions & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
- [Open Source compliance](#open-source-compliance)
- [Documentation](#documentation)
- [Publish a new public version](#publish-a-new-public-version)
- [Recommended: Using GitHub Release (Automatic)](#recommended-using-github-release-automatic)
- [Alternative: Using Workflow Dispatch (Manual)](#alternative-using-workflow-dispatch-manual)
- [Publish a new dev version](#publish-a-new-dev-version)
- [Using GitHub Actions Workflow](#using-github-actions-workflow)
- [Work with Datadog's Frontend monorepo](#work-with-datadogs-frontend-monorepo)
- [Requirements](#requirements)
- [Develop on both our monorepo and `build-plugins` locally](#develop-on-both-our-monorepo-and-build-plugins-locally)
Expand Down Expand Up @@ -293,6 +296,8 @@ We try to keep the documentation as up to date as possible.

## Publish a new public version

### Recommended: Using GitHub Release (Automatic)

1. Run [this action](https://github.com/DataDog/build-plugins/actions/workflows/bump.yaml) with the type of bump you need (`patch`, `minor`, `major`) and keep the `master` branch as target.

![Bump workflow](/packages/assets/src/publish/run-workflow.png)
Expand Down Expand Up @@ -323,27 +328,44 @@ We try to keep the documentation as up to date as possible.

Usually, after 4-5min, your version will be available from NPM.

### Alternative: Using Workflow Dispatch (Manual)

## Publish a new dev version
You can also manually trigger the [publish workflow](https://github.com/DataDog/build-plugins/actions/workflows/publish.yaml) from the `master` branch:

You can publish a version in the `dev` channel so you can easily test your changes in a different repository's CI:
1. Ensure you're on the `master` branch
2. Update the version in package.json if needed (via the bump workflow or manually)
3. Go to the [publish workflow](https://github.com/DataDog/build-plugins/actions/workflows/publish.yaml)
4. Click "Run workflow"
5. Select the `master` branch
6. Set `channel` to `latest`
7. Leave `version` empty (it will use the version from package.json)
8. Run the workflow

1. First you need to bump the version with a marker for the channel, ex: `0.4.2-dev.0` so we don't occupy a version of the `latest` channel.
> [!IMPORTANT]
> When publishing to the `latest` channel from `master`, you cannot provide a custom version, the workflow will use the version from package.json to ensure version integrity.

```bash
# Set your dev version locally (you may need to run it twice to circonvent a yarn bug)
yarn version:all 0.4.2-dev
```

2. Then publish the packages (you'll need an NPM token for this):
## Publish a new dev version

```bash
# First add your write token
yarn config set npmAuthToken $NPM_WRITE_TOKEN
You can publish a version in the `dev` channel so you can easily test your changes in a different repository's CI.

# Publish everything to the dev channel
yarn publish:all --tag=dev
```
### Using GitHub Actions Workflow

The easiest way to publish a dev version is using the GitHub Actions workflow:

1. Go to the [publish workflow](https://github.com/DataDog/build-plugins/actions/workflows/publish.yaml)
2. Click "Run workflow"
3. Select your feature branch (or `master` if publishing from there)
4. Set `channel` to `dev`
5. Set `version` to your dev version (e.g., `3.0.9-dev.0`)
- The version **must** follow the format `X.Y.Z-dev.N`
- For example: `3.0.9-dev.0`, `3.0.9-dev.1`, etc.
6. Run the workflow

> [!NOTE]
> - Dev versions can be published from any branch
> - You can provide a custom version when publishing to the `dev` channel
> - The workflow will validate the version format and fail if it doesn't match `X.Y.Z-dev.N`

Wait a few minutes, and you're good to go.

Expand Down Expand Up @@ -398,21 +420,14 @@ This will update the versions of all the plugins we use in the monorepo (webpack

### Publish a dev/alpha/beta version of the plugins to consume in Datadog's Frontend monorepo

If you want to test your `build-plugins`'s changes in our monorepo's CI, you can publish a dev version of the plugins:
If you want to test your `build-plugins`'s changes in our monorepo's CI, you can publish a dev version of the plugins.

```bash
# Use a version with a marker for the channel, ex: 2.5.1-dev-0
yarn version:all 2.5.1-dev-0

# Publish everything to the dev channel
# You will need $NPM_DD_WRITE_TOKEN set in your environment
YARN_NPM_AUTH_TOKEN=$NPM_DD_WRITE_TOKEN yarn publish:all --tag=dev
```
Follow the instructions in [Publish a new dev version](#publish-a-new-dev-version) to publish your dev version (e.g., `2.5.1-dev.0`).

Once published, in the repository:
Once published, in the monorepo:

```bash
yarn update-build-plugins 2.5.1-dev-0
yarn update-build-plugins 2.5.1-dev.0
```

Commit and push the changes.
Expand Down