-
Notifications
You must be signed in to change notification settings - Fork 2
131 lines (108 loc) · 4.52 KB
/
Copy pathprerelease.yaml
File metadata and controls
131 lines (108 loc) · 4.52 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
name: Publish prerelease packages on NPM
permissions:
id-token: write # Required for OIDC - https://docs.npmjs.com/trusted-publishers#supported-cicd-providers
contents: read
packages: read
on:
release:
types: [created]
jobs:
validate-release:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Validate release type
run: |
# Check if this is a prerelease
if [[ "${{ github.event.release.prerelease }}" != "true" ]]; then
echo "❌ This workflow is for prereleases only. Please use the main release workflow for production releases."
exit 1
fi
# Check if the tag matches the version in lerna.json
RELEASE_VERSION="${{ github.event.release.tag_name }}"
LERNA_VERSION=$(node -p "require('./lerna.json').version")
if [[ "v$LERNA_VERSION" != "$RELEASE_VERSION" ]]; then
echo "❌ Release tag $RELEASE_VERSION doesn't match lerna.json version v$LERNA_VERSION"
exit 1
fi
echo "✅ Release validation passed"
build-and-publish:
runs-on: ubuntu-latest
environment: production
needs: validate-release
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '18.x'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build packages
run: |
export BUILD_MODE=release
yarn build
- name: Create packages
run: yarn lerna run pack --stream
- name: Determine npm tag
id: npm-tag
run: |
RELEASE_TAG="${{ github.event.release.tag_name }}"
# Check if the release tag contains "preview"
if [[ "$RELEASE_TAG" =~ .*preview.* ]]; then
echo "tag=preview" >> "$GITHUB_OUTPUT"
echo "Using 'preview' npm tag for release $RELEASE_TAG"
else
echo "tag=alpha" >> "$GITHUB_OUTPUT"
echo "Using 'alpha' npm tag for release $RELEASE_TAG"
fi
- name: Publish core package
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ENV_NPM_TOKEN }}" > ~/.npmrc
npm config set access public
cd packages/core
npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.ENV_NPM_TOKEN }}
- name: Wait for core package to be available
run: |
# Get the version from lerna.json
VERSION=$(node -p "require('./lerna.json').version")
PACKAGE_NAME="@datadog/flagging-core"
echo "Waiting for $PACKAGE_NAME@$VERSION to be available on npm..."
echo "This may take a few minutes due to npm registry propagation..."
# Wait up to 5 minutes (300 seconds) with 10-second intervals
for i in {1..30}; do
echo "Attempt $i/30: Checking if $PACKAGE_NAME@$VERSION is available..."
# Try to fetch the package info from npm
if npm view "$PACKAGE_NAME@$VERSION" --json > /dev/null 2>&1; then
echo "✅ $PACKAGE_NAME@$VERSION is now available on npm!"
echo "Package details:"
npm view "$PACKAGE_NAME@$VERSION" --json
break
fi
if [ $i -eq 30 ]; then
echo "❌ Timeout: $PACKAGE_NAME@$VERSION is still not available after 5 minutes"
echo "This might indicate an issue with the npm publish or registry propagation"
exit 1
fi
echo "Package not yet available, waiting 10 seconds..."
sleep 10
done
- name: Publish browser package
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ENV_NPM_TOKEN }}" > ~/.npmrc
npm config set access public
cd packages/browser
npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.ENV_NPM_TOKEN }}
- name: Publish node-server package
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ENV_NPM_TOKEN }}" > ~/.npmrc
npm config set access public
cd packages/node-server
npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.ENV_NPM_TOKEN }}