-
Notifications
You must be signed in to change notification settings - Fork 905
78 lines (67 loc) · 2.58 KB
/
nigthly-release.yml
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
name: Nightly Release
on:
schedule:
# This runs at 00:00 UTC every day
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
nightly:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3
with:
ref: 'main'
persist-credentials: false
- name: 'Setup Node v20'
uses: actions/setup-node@v3
with:
node-version: '20'
cache: yarn
- name: Install dependencies
run: yarn --frozen-lockfile
- name: 'Setup git user'
run: |
git config user.name "${{ github.actor }}"
git config user.email "[email protected]"
- name: 'Check for new commits'
id: check
run: |
LAST_COMMIT=$(git rev-parse HEAD)
DAY_BEFORE=$(date -u -d "yesterday" '+%Y-%m-%dT%H:%M:%SZ')
COMMITS=$(git log --since="$DAY_BEFORE" --format="%H" -n 1)
if [[ "$LAST_COMMIT" == "$COMMITS" ]]; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- name: 'Prelease'
if: steps.check.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
# Get the current commit hash
COMMIT_HASH=$(git rev-parse --short HEAD)
# Get the current date
DATE=$(date +%Y%m%d)
# Get the version from package.json and split into an array
IFS='.' read -ra VERSION_ARRAY <<< "$(node -p -e "require('./packages/cli/package.json').version")"
MAJOR_VERSION=${VERSION_ARRAY[0]}
MINOR_VERSION=${VERSION_ARRAY[1]}
PATCH_VERSION=${VERSION_ARRAY[2]}
# If PATCH_VERSION contains a '-', strip everything after it
if echo $PATCH_VERSION | grep -q '-'; then
PATCH_VERSION=${PATCH_VERSION%%-*}
fi
PRERELEASE_NAME="nightly"
# Create a version string that includes the commit hash and date
VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${PRERELEASE_NAME}-${DATE}-${COMMIT_HASH}"
npx lerna version "$VERSION" --force-publish --no-push --allow-branch 'main' --preid $PRERELEASE_NAME --yes
npx lerna publish from-git --dist-tag $PRERELEASE_NAME --no-changelog --yes --loglevel verbose
- name: 'Print Lerna Debug Log'
if: always() && steps.check.outputs.changed == 'true'
run: |
echo "Contents of lerna-debug.log:"
cat lerna-debug.log