From 7fd0e1edf397cd31ce1f70ca45a6869c0c0b1e72 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Fri, 7 Mar 2025 18:44:54 +0300 Subject: [PATCH] make releases manual process --- .github/workflows/create-release.yml | 81 ++++++++++++++++++++++++++++ .github/workflows/main.yml | 79 --------------------------- 2 files changed, 81 insertions(+), 79 deletions(-) create mode 100644 .github/workflows/create-release.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000..a3c11c0f --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,81 @@ +name: Create New Release + +on: + workflow_dispatch: + inputs: + new_tag: + description: 'Tag name for the new release' + required: true + +jobs: + create_release: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get latest release tag from GitHub + id: latest_release + uses: actions/github-script@v6 + with: + script: | + try { + const latestRelease = await github.rest.repos.getLatestRelease({ + owner: context.repo.owner, + repo: context.repo.repo + }); + core.info(`Latest release tag: ${latestRelease.data.tag_name}`); + core.setOutput('last_release', latestRelease.data.tag_name); + } catch (error) { + core.info("No previous release found."); + // If no release exists, output an empty string. + core.setOutput('last_release', ''); + } + + - name: Set new release tag from input + id: new_tag + run: | + echo "NEW_TAG=${{ github.event.inputs.new_tag }}" >> $GITHUB_OUTPUT + + - name: Generate commit log for new release + id: commits + run: | + LAST_RELEASE="${{ steps.latest_release.outputs.last_release }}" + NEW_TAG="${{ steps.new_tag.outputs.NEW_TAG }}" + + if [ -z "$NEW_TAG" ]; then + echo "No new tag provided. Exiting." + exit 1 + fi + + if [ -z "${LAST_RELEASE}" ]; then + echo "No previous release found, using the repository’s initial commit as the starting point." + FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD) + RANGE="${FIRST_COMMIT}..${NEW_TAG}" + else + RANGE="${LAST_RELEASE}..${NEW_TAG}" + fi + + echo "Comparing commits between: ${RANGE}" + LOG=$(git log "${RANGE}" --no-merges --pretty=format:"- %h %s by %an") + + echo "LOG<> "$GITHUB_ENV" + echo "$LOG" >> "$GITHUB_ENV" + echo "EOF" >> "$GITHUB_ENV" + + # Create or update the GitHub release for the new tag. + - name: Create / Update GitHub Release for new tag + uses: softprops/action-gh-release@master + with: + tag_name: ${{ steps.new_tag.outputs.NEW_TAG }} + name: "${{ steps.new_tag.outputs.NEW_TAG }}" + body: ${{ env.LOG }} + append_body: false + generate_release_notes: true + make_latest: true + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1b594ce3..b953422d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -189,82 +189,3 @@ jobs: with: entrypoint: node args: /opt/docker-readme-sync/sync - - create_release: - needs: push-build - runs-on: ubuntu-latest - if: (endsWith(github.ref, github.event.repository.default_branch) && success()) || (github.event_name == 'workflow_dispatch' && github.event.inputs.create_release == 'true') - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # so we can see all tags + full history - - - name: Determine current branch - id: branch - run: | - # github.ref_name should be "master", "main", or your branch name - echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT - - - name: Fetch the two latest tags for this branch - id: last_two_tags - run: | - git fetch --tags - - BRANCH_NAME="${{ steps.branch.outputs.BRANCH_NAME }}" - echo "Current branch: $BRANCH_NAME" - - # List tags matching "branchname-*" and sort by *creation date* descending - # Then pick the top 2 - LATEST_TAGS=$(git tag --list "${BRANCH_NAME}-*" --sort=-creatordate | head -n 2) - TAG_COUNT=$(echo "$LATEST_TAGS" | wc -l) - - echo "Found tags:" - echo "$LATEST_TAGS" - - if [ "$TAG_COUNT" -lt 2 ]; then - echo "Not enough tags found (need at least 2) to compare commits." - echo "NOT_ENOUGH_TAGS=true" >> "$GITHUB_OUTPUT" - exit 0 - fi - - # The first line is the newest tag - TAG_NEWEST=$(echo "$LATEST_TAGS" | sed -n '1p') - # The second line is the previous newest - TAG_PREVIOUS=$(echo "$LATEST_TAGS" | sed -n '2p') - - echo "Newest tag: $TAG_NEWEST" - echo "Previous tag: $TAG_PREVIOUS" - - # Expose them as outputs for next step - echo "NOT_ENOUGH_TAGS=false" >> "$GITHUB_OUTPUT" - echo "TAG_NEWEST=$TAG_NEWEST" >> "$GITHUB_OUTPUT" - echo "TAG_PREVIOUS=$TAG_PREVIOUS" >> "$GITHUB_OUTPUT" - - - name: Generate commit log for newest tag - id: commits - if: steps.last_two_tags.outputs.NOT_ENOUGH_TAGS != 'true' - run: | - TAG_NEWEST="${{ steps.last_two_tags.outputs.TAG_NEWEST }}" - TAG_PREVIOUS="${{ steps.last_two_tags.outputs.TAG_PREVIOUS }}" - - echo "Comparing commits between: $TAG_PREVIOUS..$TAG_NEWEST" - LOG=$(git log "$TAG_PREVIOUS".."$TAG_NEWEST" --no-merges --pretty=format:"- %h %s by %an") - - echo "LOG<> "$GITHUB_ENV" - echo "$LOG" >> "$GITHUB_ENV" - echo "EOF" >> "$GITHUB_ENV" - - - name: Create / Update GitHub Release for the newest tag - if: steps.last_two_tags.outputs.NOT_ENOUGH_TAGS != 'true' - uses: softprops/action-gh-release@master - with: - tag_name: ${{ steps.last_two_tags.outputs.TAG_NEWEST }} - name: "${{ steps.last_two_tags.outputs.TAG_NEWEST }}" - body: ${{ env.LOG }} - append_body: true - generate_release_notes: true - make_latest: true - draft: false - prerelease: false - token: ${{ secrets.GITHUB_TOKEN }}