|
| 1 | +name: Draft release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + versionBump: |
| 7 | + description: 'Version bump' |
| 8 | + type: choice |
| 9 | + required: true |
| 10 | + default: 'patch' |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + - exact-version |
| 16 | + |
| 17 | + exactVersion: |
| 18 | + description: 'Exact version: (Only effective selecting "exact-version" as version bump)' |
| 19 | + required: false |
| 20 | + |
| 21 | +jobs: |
| 22 | + prepare-release: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + # NOTE: this is necessary to get the full history |
| 29 | + # and check if tags are already present |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Setup Node.js Environment |
| 33 | + uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: 20.18.1 |
| 36 | + |
| 37 | + - name: Determine Next Version |
| 38 | + shell: bash |
| 39 | + env: |
| 40 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + run: | |
| 42 | + set -e |
| 43 | +
|
| 44 | + VERSION_BUMP=${{ github.event.inputs.versionBump }} |
| 45 | +
|
| 46 | + if [[ "$VERSION_BUMP" == "major" || "$VERSION_BUMP" == "minor" || "$VERSION_BUMP" == "patch" ]]; then |
| 47 | + PREV_VERSION_TAG=$(gh api repos/:owner/:repo/releases --jq '. | map(select(.draft == false)) | .[0] | .tag_name') |
| 48 | + PREV_VERSION=$(npx semver --coerce ${PREV_VERSION_TAG}) |
| 49 | +
|
| 50 | + NEXT_VERSION=$(npx semver -i $VERSION_BUMP $PREV_VERSION) |
| 51 | + else |
| 52 | + NEXT_VERSION=${{ github.event.inputs.exactVersion }} |
| 53 | + fi |
| 54 | +
|
| 55 | + # Validates the version before using it |
| 56 | + npx semver v"${NEXT_VERSION}" |
| 57 | +
|
| 58 | + npm version "${NEXT_VERSION}" --no-git-tag-version |
| 59 | + echo "RELEASE_TAG=v${NEXT_VERSION}" >> "$GITHUB_ENV" |
| 60 | +
|
| 61 | + - name: Validate release tag |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + if [ -z "${RELEASE_TAG}" ]; then |
| 65 | + echo "RELEASE_TAG is not set or is empty" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then |
| 70 | + echo "Error: Tag $RELEASE_TAG already exists" |
| 71 | + echo "If you are trying to re-create a draft release with this version, please delete the release and the tag first." |
| 72 | + echo "If this version has already been release consider using a different one." |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Bump mongosh and package versions |
| 77 | + run: | |
| 78 | + set -e |
| 79 | + echo Bumping mongosh versions to ${RELEASE_TAG} and packages |
| 80 | +
|
| 81 | + MONGOSH_RELEASE_VERSION=${RELEASE_TAG} npm run bump |
| 82 | +
|
| 83 | + - name: Create Draft Release |
| 84 | + run: | |
| 85 | + set -e |
| 86 | + echo Creating draft release for: "${RELEASE_TAG}" |
| 87 | +
|
| 88 | + git tag ${RELEASE_TAG} |
| 89 | + git push origin ${RELEASE_TAG} |
| 90 | +
|
| 91 | + shell: bash |
| 92 | + env: |
| 93 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + |
0 commit comments