-
Notifications
You must be signed in to change notification settings - Fork 12
142 lines (129 loc) · 5.39 KB
/
Copy pathpublish.yaml
File metadata and controls
142 lines (129 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Publish packages on NPM
on:
release:
types: [ released ]
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:
name: Publish to NPM
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # Full history needed for yarn version to find ancestor with master/main
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
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' }}"
# For release events, github.ref_name is the tag name, not the branch.
# Get the branch name from the release target_commitish or default branch.
if [ "${{ github.event_name }}" = "release" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
else
BRANCH="${{ github.ref_name }}"
fi
# 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 "branch=$BRANCH" >> $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="${{ steps.channel.outputs.branch }}"
# 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
- 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"
-H "DD-API-KEY: $DATADOG_API_KEY"
)
DATA="{
\"ddsource\": \"github\",
\"service\": \"build-plugins\",
\"message\": \"Version published to $CHANNEL channel: $VERSION\",
\"status\": \"success\",
\"env\": \"production\",
\"team\": \"language-foundations\",
\"version\": \"$VERSION\",
\"channel\": \"$CHANNEL\"
}"
URL="https://http-intake.logs.datadoghq.com/api/v2/logs"
curl -X POST "${HEADERS[@]}" -d "$DATA" "$URL"
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}