|
| 1 | +name: Nightly Release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # This runs at 00:00 UTC every day |
| 6 | + - cron: "0 0 * * *" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + nightly: |
| 11 | + if: github.ref == 'refs/heads/main' |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: 'Checkout' |
| 15 | + uses: actions/checkout@v3 |
| 16 | + with: |
| 17 | + ref: 'main' |
| 18 | + persist-credentials: false |
| 19 | + |
| 20 | + - name: 'Setup Node v20' |
| 21 | + uses: actions/setup-node@v3 |
| 22 | + with: |
| 23 | + node-version: '20' |
| 24 | + env: |
| 25 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 26 | + |
| 27 | + - name: 'Setup git user' |
| 28 | + run: | |
| 29 | + git config user.name "${{ github.actor }}" |
| 30 | + git config user.email "[email protected]" |
| 31 | +
|
| 32 | + - name: 'Check for new commits' |
| 33 | + id: check |
| 34 | + run: | |
| 35 | + LAST_COMMIT=$(git rev-parse HEAD) |
| 36 | + DAY_BEFORE=$(date -u -d "yesterday" '+%Y-%m-%dT%H:%M:%SZ') |
| 37 | + COMMITS=$(git log --since="$DAY_BEFORE" --format="%H" -n 1) |
| 38 | + if [[ "$LAST_COMMIT" == "$COMMITS" ]]; then |
| 39 | + echo "::set-output name=changed::true" |
| 40 | + else |
| 41 | + echo "::set-output name=changed::false" |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: 'Prelease' |
| 45 | + if: steps.check.outputs.changed == 'true' |
| 46 | + env: |
| 47 | + GH_TOKEN: ${{ github.token }} |
| 48 | + run: | |
| 49 | + # Get the current commit hash |
| 50 | + COMMIT_HASH=$(git rev-parse --short HEAD) |
| 51 | + # Get the current date |
| 52 | + DATE=$(date +%Y%m%d) |
| 53 | + # Get the version from package.json and split into an array |
| 54 | + IFS='.' read -ra VERSION_ARRAY <<< "$(node -p -e "require('./packages/cli/package.json').version")" |
| 55 | +
|
| 56 | + MAJOR_VERSION=${VERSION_ARRAY[0]} |
| 57 | + MINOR_VERSION=${VERSION_ARRAY[1]} |
| 58 | + PATCH_VERSION=${VERSION_ARRAY[2]} |
| 59 | +
|
| 60 | + # If PATCH_VERSION contains a '-', strip everything after it |
| 61 | + if echo $PATCH_VERSION | grep -q '-'; then |
| 62 | + PATCH_VERSION=${PATCH_VERSION%%-*} |
| 63 | + fi |
| 64 | +
|
| 65 | + PRERELEASE_NAME="nightly" |
| 66 | +
|
| 67 | + # Create a version string that includes the commit hash and date |
| 68 | + VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${PRERELEASE_NAME}-${DATE}-${COMMIT_HASH}" |
| 69 | +
|
| 70 | + npx lerna version "$VERSION" from-package --force-publish --no-push --allow-branch 'main' --preid $PRERELEASE_NAME --yes |
| 71 | + npx lerna publish from-git --dist-tag $PRERELEASE_NAME --no-changelog --yes |
0 commit comments