diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 000000000..cf33086a4 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,75 @@ +name: Build Image + +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag to build' + required: true + type: string + deployment-env: + description: 'Deployment environment' + type: choice + options: + - staging + - production + workflow_call: + inputs: + tag: + description: 'Tag to build' + required: true + type: string + deployment-env: + description: 'Deployment environment' + type: string + +concurrency: + group: ${{ github.workflow }} + +permissions: + contents: write + packages: write + +jobs: + build: + name: Build Docker image + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine registry and app + id: determine + run: | + tag=${{ inputs.tag }} + force_build="" + + if [[ "$tag" == console-api/* ]]; then + echo "registry=${{ vars.API_REGISTRY }}" >> $GITHUB_ENV + echo "app=api" >> $GITHUB_ENV + elif [[ "$tag" == console-web/* ]]; then + echo "registry=${{ vars.WEB_REGISTRY }}" >> $GITHUB_ENV + echo "app=deploy-web" >> $GITHUB_ENV + echo "force_build=-f" >> $GITHUB_ENV + else + echo "Error: Unknown tag format" + exit 1 + fi + + tag="${tag#*/}" + tag="${tag#v}" + echo "tag=$tag" >> $GITHUB_ENV + + - name: Build Docker image + env: + DEPLOYMENT_ENV: ${{ inputs.deployment-env }} + run: | + ./packages/docker/script/build.sh -r ${{ env.registry }} -t ${{ env.tag }} -a ${{ env.app }} ${{ env.force_build }} \ No newline at end of file diff --git a/.github/workflows/create-github-release.yml b/.github/workflows/create-github-release.yml new file mode 100644 index 000000000..617437691 --- /dev/null +++ b/.github/workflows/create-github-release.yml @@ -0,0 +1,84 @@ +name: Create GitHub Release + +on: + workflow_call: + inputs: + app: + description: 'The app to release' + required: true + type: string + outputs: + version: + description: 'The version released' + value: ${{ jobs.release.outputs.version }} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.app }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + release: + name: Create GitHub Release + runs-on: ubuntu-latest + + outputs: + version: ${{ steps.bumps.outputs.version }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get Version and Changelog Updates + id: bumps + run: | + package_file="apps/${{ inputs.app }}/package.json" + + if [ ! -f "$package_file" ]; then + echo "Error: Package file $package_file does not exist." + exit 1 + fi + + current_version=$(jq -r '.version' "$package_file") + git_tag=$current_version + + if [ "${{ inputs.app }}" = "deploy-web" ]; then + git_tag="console-web/v$git_tag" + elif [ "${{ inputs.app }}" = "api" ]; then + git_tag="console-api/v$git_tag" + else + echo "Error: Unsupported app type '${{ inputs.app }}'." + exit 1 + fi + + has_tag=$(git rev-parse "$git_tag" >/dev/null 2>&1 && echo "true" || echo "false") + + if [ "$has_tag" = "false" ]; then + echo "version=$git_tag" >> $GITHUB_OUTPUT + echo "version=$git_tag" + + changelog=$(script/extract-changelog.sh "$current_version" "apps/${{ inputs.app }}/CHANGELOG.md") + + if [ -n "$changelog" ]; then + echo "changelog=$changelog" + echo "changelog<> $GITHUB_OUTPUT + echo "$changelog" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + fi + fi + + - name: Create Release + if: ${{ steps.bumps.outputs.version != '' }} + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.bumps.outputs.version }} + release_name: ${{ steps.bumps.outputs.version }} + body: ${{ steps.bumps.outputs.changelog }} + prerelease: true \ No newline at end of file diff --git a/.github/workflows/create-pre-release-pr.yml b/.github/workflows/create-pre-release-pr.yml new file mode 100644 index 000000000..162abaef4 --- /dev/null +++ b/.github/workflows/create-pre-release-pr.yml @@ -0,0 +1,92 @@ +name: Create Pre-Release PR + +on: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +env: + NODE_VERSION: 20.14.0 + GITHUB_EMAIL: "ci@akash.network" + GITHUB_NAME: "CI" + +jobs: + check-releasability: + name: Check if is Releasable + runs-on: ubuntu-latest + outputs: + is-releasable: ${{ steps.check.outputs.is-releasable }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check if is Releasable + id: check + run: | + last_commit=$(git log -1 --pretty=%B) + if [[ $last_commit == "chore(release): released version"* ]]; then + echo "is-releasable=false" >> $GITHUB_OUTPUT + else + echo "is-releasable=true" >> $GITHUB_OUTPUT + fi + + create-pr: + name: Create Pre-Release PR with Updated Changelogs and Versions + needs: check-releasability + if: needs.check-releasability.outputs.is-releasable == 'true' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Restore root node_modules cache + uses: actions/cache@v4 + id: cache + with: + path: | + node_modules + apps/api/node_modules + apps/deploy-web/node_modules + packages/*/node_modules + key: common-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: npm ci -w packages/releaser + + - name: Generate releases and build docker images + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.email "${{ env.GITHUB_EMAIL }}" + git config --global user.name "${{ env.GITHUB_NAME }}" + npm run release -w apps/api -- --verbose --ci + npm run release -w apps/deploy-web -- --verbose --ci + + - name: Cleanup Previous Release Branch + run: | + git branch -D release/bumps || true + + - name: Commit and Create PR + uses: peter-evans/create-pull-request@v7 + with: + token: '${{ github.token }}' + branch: release/bumps + base: main + title: "Release bumps" + body: "This is an automated PR to update the changelogs and versions for the next release. Merging it will trigger release adn build workflows" \ No newline at end of file diff --git a/.github/workflows/release-all-apps.yml b/.github/workflows/release-all-apps.yml deleted file mode 100644 index b3241cee2..000000000 --- a/.github/workflows/release-all-apps.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Release All Apps - -on: - push: - branches: ["main"] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - release: - name: Release - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 20.14.0 - - - name: Restore root node_modules cache - uses: actions/cache@v4 - id: cache - with: - path: | - node_modules - apps/api/node_modules - apps/deploy-web/node_modules - packages/*/node_modules - key: common-${{ runner.os }}-${{ hashFiles('package-lock.json') }} - - - name: Install dependencies - if: steps.cache.outputs.cache-hit != 'true' - run: npm ci - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Get the latest tag - id: latest_tag - run: | - output="value=$(git describe --tags --abbrev=0)" - echo $output - echo $output >> $GITHUB_OUTPUT - - - name: Generate releases and build docker images - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.email "ci@akash.network" - git config --global user.name "CI" - npm run release -w apps/api -- --preRelease=beta --verbose --ci -r ${{ vars.API_REGISTRY }} - npm run release -w apps/deploy-web -- --preRelease=beta -f --verbose --ci -r ${{ vars.WEB_REGISTRY }} - - - name: Trigger deployments - run: | - latest_tag=${{ steps.latest_tag.outputs.value }} - api_tags=$(git tag --sort=-creatordate --merged | grep '^console-api/v') - new_api_tag=$(echo "$api_tags" | awk -v latest="$latest_tag" '$0 > latest' | head -n 1) - - if [ -z "$new_api_tag" ]; then - echo "No new console-api tag found. Skipping api deployment." - else - echo "Dispatching deploy workflow for: $new_api_tag" - curl -X POST \ - -H "Authorization: token ${{ secrets.AKASH_GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${{ github.repository }}/actions/workflows/deploy-api-to-akash.yml/dispatches \ - -d "{\"ref\": \"main\", \"inputs\": { \"tag\": \"$new_api_tag\" }}" - fi - diff --git a/.github/workflows/release-api.yml b/.github/workflows/release-api.yml new file mode 100644 index 000000000..0ea0a8e08 --- /dev/null +++ b/.github/workflows/release-api.yml @@ -0,0 +1,27 @@ +name: Release API + +on: + push: + branches: + - main + paths: + - 'apps/api/package.json' + +jobs: + release: + name: Create Release + uses: ./.github/workflows/create-github-release.yml + secrets: inherit + with: + app: api + + build: + needs: release + name: Build Docker image + uses: ./.github/workflows/build-image.yml + secrets: inherit + permissions: + contents: write + packages: write + with: + tag: ${{ needs.release.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/release-app.yml b/.github/workflows/release-app.yml deleted file mode 100644 index 5322ffcdd..000000000 --- a/.github/workflows/release-app.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: Release App - -on: - workflow_dispatch: - inputs: - app: - type: choice - description: Which app to release - options: - - api - - deploy-web - required: true - release-type: - type: choice - description: Which app to release - options: - - prod - - beta - default: prod - force-build: - type: boolean - description: Rebuild the Docker image - default: false - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 20.14.0 - - - name: Restore root node_modules cache - uses: actions/cache@v4 - id: cache - with: - path: | - node_modules - apps/${{ github.event.inputs.app }}/node_modules - packages/*/node_modules - key: ${{ github.event.inputs.app }}-${{ runner.os }}-${{ hashFiles('package-lock.json') }} - - - name: Install dependencies - if: steps.cache.outputs.cache-hit != 'true' - run: npm ci - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build the Docker images - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.email "ci@akash.network" - git config --global user.name "CI" - - pre_release="" - if [[ "${{ github.event.inputs.release-type }}" == 'beta' ]]; then - prerelease="--preRelease=beta" - fi - - force_build="" - if [[ "${{ github.event.inputs.force-build }}" == 'true' ]]; then - force_build="-f" - fi - - repo="${{ github.event.inputs.app == 'api' && vars.API_REGISTRY || vars.WEB_REGISTRY }}" - - npm run release -w apps/${{ github.event.inputs.app }} -- $pre_release $force_build --verbose --ci -r $repo \ No newline at end of file diff --git a/.github/workflows/release-deploy-web.yml b/.github/workflows/release-deploy-web.yml new file mode 100644 index 000000000..8d016d34a --- /dev/null +++ b/.github/workflows/release-deploy-web.yml @@ -0,0 +1,40 @@ +name: Release Deploy Web + +on: + push: + branches: + - main + paths: + - 'apps/deploy-web/package.json' + +jobs: + release: + name: Create Release + uses: ./.github/workflows/create-github-release.yml + secrets: inherit + with: + app: deploy-web + + build-beta: + needs: release + name: Build Beta Docker image + uses: ./.github/workflows/build-image.yml + secrets: inherit + permissions: + contents: write + packages: write + with: + tag: ${{ needs.release.outputs.version }}-beta + deployment-env: staging + + build-prod: + needs: release + name: Build Prod Docker image + uses: ./.github/workflows/build-image.yml + secrets: inherit + permissions: + contents: write + packages: write + with: + tag: ${{ needs.release.outputs.version }} + deployment-env: production \ No newline at end of file diff --git a/apps/api/package.json b/apps/api/package.json index d83b4e8ea..66c0845ef 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -99,7 +99,6 @@ "@akashnetwork/docker": "*", "@akashnetwork/releaser": "*", "@faker-js/faker": "^8.4.1", - "@release-it/conventional-changelog": "github:akash-network/conventional-changelog#feature/pre-release", "@types/http-assert": "^1.5.5", "@types/http-errors": "^2.0.4", "@types/jest": "^29.5.12", @@ -124,7 +123,6 @@ "nodemon-webpack-plugin": "^4.8.2", "prettier": "^3.3.0", "prettier-plugin-tailwindcss": "^0.6.1", - "release-it": "^17.6.0", "supertest": "^6.1.5", "ts-jest": "^29.1.4", "ts-loader": "^9.2.5", diff --git a/apps/deploy-web/package.json b/apps/deploy-web/package.json index 604343115..b60625e42 100644 --- a/apps/deploy-web/package.json +++ b/apps/deploy-web/package.json @@ -121,7 +121,6 @@ "@next/bundle-analyzer": "^14.0.1", "@octokit/openapi-types": "^22.2.0", "@playwright/test": "^1.45.0", - "@release-it/conventional-changelog": "github:akash-network/conventional-changelog#feature/pre-release", "@types/auth0": "^2.35.3", "@types/file-saver": "^2.0.5", "@types/gtag.js": "^0.0.20", @@ -142,7 +141,6 @@ "postcss-nesting": "^12.0.2", "prettier": "^3.3.0", "prettier-plugin-tailwindcss": "^0.6.1", - "release-it": "^17.6.0", "tailwindcss": "^3.4.3", "typescript": "5.1.3" }, diff --git a/doc/release-workflow.md b/doc/release-workflow.md index 4e587b6d0..2891a97ba 100644 --- a/doc/release-workflow.md +++ b/doc/release-workflow.md @@ -6,46 +6,32 @@ This release workflow leverages **release-it**, **Docker**, **Docker Compose**, ## Release Flow -The release process is divided into two key stages: pre-release (beta) and final release. This is done using SemVer conventions. +### Summary +1. Create a feature PR. +2. Make sure all the checks pass. +3. Rebase and merge the PR. +4. GitHub Actions creates a pre-release PR with updated changelog and version. +5. Merge the pre-release PR. +6. GitHub Actions creates relevant GitHub releases and builds relevant Docker images. +7. Utilize manual GitHub Actions to deploy the services. -### 1. Pre-Release (Beta) +### Automated Versioning and Changelogs -To create a **pre-release** (beta) version, the following command is used. This will create a beta version using the `release-it` tool with the specified options: +The release process is conducted using SemVer conventions. +To update a changelog and bump a version the following command is used: ```bash -npm run release -w apps/$APP -- --preRelease=beta --verbose --ci -r $REGISTRY +npm run release -w apps/$APP -- --verbose --ci ``` #### Key Options: -- `--preRelease`: Marks the release as a beta pre-release. - `--verbose`: Provides detailed output for troubleshooting. - `--ci`: Ensures the release runs in a continuous integration environment. -- `-r`: Registry to push the Docker image. -### 2. Final Release - -For creating a final release, the command below is used. This will bump the version based on SemVer and push the release. - -```bash -npm run release -w apps/$APP -- --verbose --ci -r $REGISTRY -``` - -This should be run manually after validating the beta pre-release. Manual workflow is available in the GitHub Actions interface. - -## GitHub Actions Workflow - -### Pre-Release on Merge - -When a merge occurs on the `main` branch, a **beta** version is automatically created using GitHub Actions. The workflow is triggered by the merge event, ensuring that each change is reflected in a pre-release. - -### Manual Release - -Final releases are not triggered automatically. Instead, they are initiated manually via the GitHub Actions interface. This allows for flexibility in verifying and ensuring that the beta version is stable before creating an official release. ## Customs scripts Scripts that are used in the release process are located in the `docker` package. These scripts are used to build Docker images, deploy services, and manage the release process. Check out the [README.md](../packages/docker/README.md) for more details. `release-it` config is also shared via local packages. ## Roadmap -- add alpha pre-release once development is provisioned - implement actual deployment to infra as currently only the Docker image is build and pushed \ No newline at end of file diff --git a/packages/docker/script/build.sh b/packages/docker/script/build.sh index 36066761c..cda5a2820 100755 --- a/packages/docker/script/build.sh +++ b/packages/docker/script/build.sh @@ -59,21 +59,12 @@ if [[ -z "$REPO" || -z "$TAG" || -z "$APP" ]]; then exit 1 fi -commits=$(git log -n 10 --pretty=format:"%H %s" -- "$(git rev-parse --show-toplevel)"/apps/${APP}) - -while IFS= read -r commit; do - MESSAGE=$(echo $commit | cut -d' ' -f2-) - -if [[ ! $MESSAGE =~ ^chore\(release\):\ released\ version && ! $MESSAGE =~ ^chore\(deploy\):\ update\ deployment\ state ]]; then - echo "Base commit: $commit" - SHA=$(echo $commit | awk '{print $1}') - break -fi -done <<< "$commits" +commit=$(git log -n 1 --pretty=format:"%H %s" -- "$(git rev-parse --show-toplevel)"/apps/${APP}) +SHA=$(echo $commit | awk '{print $1}') SCRIPTS_DIR="$(dirname "$(readlink -f "$0")")" BASE_IMAGE="${REPO}:${SHA}" -echo "using base image: ${BASE_IMAGE}" +echo "using base image ${BASE_IMAGE} for commit: \"$(echo $commit | cut -d' ' -f2-)\"" IS_BUILT_FOR_SHA=1 if [ -n "$SHA" ]; then @@ -81,47 +72,51 @@ if [ -n "$SHA" ]; then fi TAGGED_IMAGE="${REPO}:${TAG}" -IS_BUILT_FOR_TAG=$(docker manifest inspect "${TAGGED_IMAGE}" > /dev/null 2>&1; echo $?) -echo "is built for sha: ${IS_BUILT_FOR_SHA}" -echo "is built for tag: ${IS_BUILT_FOR_TAG}" +if [[ "${IS_BUILT_FOR_SHA}" -eq 0 ]]; then + echo "image is already built for sha: ${SHA}" +fi + +IS_BUILT_FOR_TAG=$(docker manifest inspect "${TAGGED_IMAGE}" > /dev/null 2>&1; echo $?) if [[ "${IS_BUILT_FOR_TAG}" -eq 0 ]]; then - echo 'image is already tagged, skipping build' + echo "image is already built for tag: ${TAG}. skipping build" + exit 0 +fi + + +if [[ "${IS_BUILT_FOR_SHA}" -eq 0 ]] && [[ "${FORCE_BUILD}" == false ]]; then + echo 'image is already tagged for sha. using existing one' + docker pull "${BASE_IMAGE}" + docker image tag "${REPO}:${SHA}" "${TAGGED_IMAGE}" + docker push "${TAGGED_IMAGE}" + exit 0 +fi + +if [[ "${IS_BUILT_FOR_SHA}" -eq 0 ]] && [[ "${FORCE_BUILD}" == true ]]; then + echo 're-building image as forced' else - if [[ "${IS_BUILT_FOR_SHA}" -eq 0 ]]; then - echo 'image is already tagged for sha. using existing one' - docker pull "${BASE_IMAGE}" - docker image tag "${REPO}:${SHA}" "${TAGGED_IMAGE}" - else - echo 'building new image' - ENV_PREFIX=$(echo $APP | tr '[:lower:]' '[:upper:]') - ENV_PREFIX=$(echo $ENV_PREFIX | tr '-' '_') - export ${ENV_PREFIX}_TAG=$TAG - export ${ENV_PREFIX}_REPO=$REPO - DEPLOYMENT_ENV="${DEPLOYMENT_ENV:-}" - - if [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - DEPLOYMENT_ENV='production' - elif [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$ ]]; then - DEPLOYMENT_ENV='staging' - elif [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9]+$ ]]; then - DEPLOYMENT_ENV='development' - fi - export DEPLOYMENT_ENV=$DEPLOYMENT_ENV - - echo "building image for ${APP} with tag ${TAG} and deployment env ${DEPLOYMENT_ENV}" - - $SCRIPTS_DIR/dc.sh build $APP - - if [[ "${FORCE_BUILD}" == false ]]; then - docker image tag "${TAGGED_IMAGE}" "${REPO}:${SHA}" - fi - fi - - if [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - docker image tag "${TAGGED_IMAGE}" "${REPO}:latest" - fi - - docker push "${REPO}" --all-tags -fi \ No newline at end of file + echo 'image is not built for sha. building a new one' +fi + +echo 'building new image' +ENV_PREFIX=$(echo $APP | tr '[:lower:]' '[:upper:]') +ENV_PREFIX=$(echo $ENV_PREFIX | tr '-' '_') +export ${ENV_PREFIX}_TAG=$TAG +export ${ENV_PREFIX}_REPO=$REPO +DEPLOYMENT_ENV="${DEPLOYMENT_ENV:-}" + +export DEPLOYMENT_ENV=$DEPLOYMENT_ENV + +echo "building image for ${APP} with tag ${TAG} and deployment env ${DEPLOYMENT_ENV}" + +$SCRIPTS_DIR/dc.sh build $APP + +if [[ "${FORCE_BUILD}" == false ]]; then + docker image tag "${TAGGED_IMAGE}" "${REPO}:${SHA}" +fi + +docker image tag "${TAGGED_IMAGE}" "${REPO}:latest" + +docker push "${TAGGED_IMAGE}" +docker push "${REPO}:latest" diff --git a/packages/releaser/.release-it.js b/packages/releaser/.release-it.js index 2aa411d4f..f8387e174 100644 --- a/packages/releaser/.release-it.js +++ b/packages/releaser/.release-it.js @@ -1,25 +1,9 @@ -const parseArgs = require('yargs-parser'); -const { addBangNotes } = require('conventional-changelog-conventionalcommits/utils') +const { addBangNotes } = require("conventional-changelog-conventionalcommits/utils"); const { DEFAULT_COMMIT_TYPES } = require("conventional-changelog-conventionalcommits"); const version = "${version}"; const packageName = process.env.npm_package_name; const scope = packageName.split("/")[1]; -const pathParts = process.env.npm_package_json.split('/'); -const app = pathParts[pathParts.length - 2]; - -const options = parseArgs(process.argv, { - string: ['repo', 'preRelease'], - boolean: ['force-build'], - alias: { r: 'repo', f: 'force-build' }, -}); - -if (!options.repo) { - console.error('"-r --repo" not specified'); - process.exit(1); -} - -const isPromotion = !options.preRelease; module.exports = { plugins: { @@ -31,31 +15,31 @@ module.exports = { path: "." }, tagPrefix: `${scope}/v`, - skipUnstable: isPromotion, - whatBump (commits) { - let level = undefined - let breakings = 0 - let features = 0 + whatBump(commits) { + let level = undefined; + let breakings = 0; + let features = 0; commits.forEach(commit => { - const isHiddenType = DEFAULT_COMMIT_TYPES.find((type) => type.type === commit.type)?.hidden || false; - addBangNotes(commit) + const isHiddenType = DEFAULT_COMMIT_TYPES.find(type => type.type === commit.type)?.hidden || false; + addBangNotes(commit); if (commit.notes.length > 0) { - breakings += commit.notes.length - level = 0 - } else if (commit.type === 'feat' || commit.type === 'feature') { - features += 1 - if (level === 2 || typeof level === 'undefined') { - level = 1 + breakings += commit.notes.length; + level = 0; + } else if (commit.type === "feat" || commit.type === "feature") { + features += 1; + if (level === 2 || typeof level === "undefined") { + level = 1; } - } else if (!isHiddenType && typeof level === 'undefined') { + } else if (!isHiddenType && typeof level === "undefined") { level = 2; } - }) + }); return { level, - reason: breakings === 1 + reason: + breakings === 1 ? `There is ${breakings} BREAKING CHANGE and ${features} features` : `There are ${breakings} BREAKING CHANGES and ${features} features` }; @@ -63,24 +47,15 @@ module.exports = { } }, git: { - push: true, + push: false, + tag: false, tagName: `${scope}/v${version}`, commitsPath: ".", commitMessage: `chore(release): released version ${scope}/v${version}`, - requireCommits: !isPromotion, - requireCommitsFail: false, + requireCommitsFail: false }, npm: { publish: false, versionArgs: ["--workspaces false"] - }, - github: { - release: true, - releaseName: `${scope}/v${version}` - }, - hooks: { - 'before:git:release': [ - `build-image -r ${options.repo} -t ${version} ${options.forceBuild ? '-f' : ''} -a ${app}`, - ], } }; diff --git a/packages/releaser/package.json b/packages/releaser/package.json index ada8e6c2d..52156b584 100644 --- a/packages/releaser/package.json +++ b/packages/releaser/package.json @@ -10,6 +10,7 @@ "dc": "./script/dc.sh" }, "dependencies": { - "yargs-parser": "^21.1.1" + "@release-it/conventional-changelog": "github:akash-network/conventional-changelog#feature/pre-release", + "release-it": "^17.6.0" } } diff --git a/script/extract-changelog.sh b/script/extract-changelog.sh new file mode 100755 index 000000000..1a5cfa958 --- /dev/null +++ b/script/extract-changelog.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: $0 " + exit 1 +fi + +tag=$1 +changelog_file=$2 + +if [ ! -f "$changelog_file" ]; then + echo "Error: Changelog file $changelog_file does not exist." + exit 1 +fi + +entry=$(awk -v tag="$tag" ' + BEGIN { found = 0 } + $0 ~ "^## \\[" tag "\\]" { found = 1; print; next } + found && $0 ~ "^## \\[" { found = 0 } + found { print } +' "$changelog_file") + +if [ -n "$entry" ]; then + echo "$entry" +fi \ No newline at end of file