From 289c4ee8c3f9a7108bc155ba117d00a494970776 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Mon, 3 Feb 2025 23:05:19 +0300 Subject: [PATCH 1/2] instead of relying on changelog being generated on commit, we rely on tag instead --- .github/workflows/changelog.yml | 6 +---- frontend/pages/changelog.vue | 41 ++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index a1fd5d85..1f9e64be 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -35,17 +35,13 @@ jobs: echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV echo "Detected Tag: $TAG_NAME on Branch: $BRANCH_NAME" - - name: Generate Changelog JSON - run: | - python .github/scripts/generate_changelog.py --repo_path . --changelog_path ./CHANGELOG-${BRANCH_NAME}.json --branch_name $BRANCH_NAME - - name: Commit and Push to GitHub Pages run: | git config --global user.name "github-actions" git config --global user.email "github-actions@github.com" git checkout gh-pages || git checkout --orphan gh-pages git pull origin gh-pages || true - mv CHANGELOG-*.json . + python .github/scripts/generate_changelog.py --repo_path . --changelog_path ./CHANGELOG-${BRANCH_NAME}.json --branch_name $BRANCH_NAME git add CHANGELOG-*.json git commit -m "Update Changelog for $TAG_NAME" git push origin gh-pages diff --git a/frontend/pages/changelog.vue b/frontend/pages/changelog.vue index 4f60e85e..91889bff 100644 --- a/frontend/pages/changelog.vue +++ b/frontend/pages/changelog.vue @@ -11,24 +11,28 @@ -
-

- - - - {{ log.tag }} Installed +
+
+

+ + + + {{ log.tag }} Installed + - -

-
    -
  • -

    - {{ commit.message }} -
    - {{ commit.sha }} - {{ moment(commit.date).fromNow() }} -

    -
  • -
+

+
+ +
+
@@ -43,7 +47,8 @@ const logs = ref([]); const api_version = ref('master'); const branch = computed(() => { - return String(api_version.value).split('-')[0] ?? 'master'; + const branch = String(api_version.value).split('-')[0] ?? 'master'; + return ['master', 'dev'].includes(branch) ? branch : 'dev'; }); const loadContent = async () => { From 8ea02be046082e0cb1a5f9baf972db34345783df Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Mon, 3 Feb 2025 23:15:15 +0300 Subject: [PATCH 2/2] no longer auto create release --- .github/workflows/auto-release.yml | 82 ++++++++++++++++++++++++++++++ .github/workflows/build.yml | 81 ----------------------------- .github/workflows/changelog.yml | 39 +++++++++++--- 3 files changed, 114 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/auto-release.yml diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 00000000..52f37987 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,82 @@ +name: Create new release. + +on: + workflow_dispatch: + +jobs: + create_release: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - 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" --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 }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 52302484..fe97296a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -231,84 +231,3 @@ jobs: with: entrypoint: node args: /opt/docker-readme-sync/sync - - create_release: - needs: publish_docker_images - runs-on: ubuntu-latest - # Example condition: run only if this is the default branch, or - # if triggered manually with input "create_release". - 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" --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 }} diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 1f9e64be..e5e5d4cb 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -29,7 +29,13 @@ jobs: - name: Get Branch Name from Tag id: branch_name run: | - TAG_NAME=$(git describe --tags --abbrev=0) + # Try to get the latest tag; if none exist, fallback to the current branch name. + TAG_NAME=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + if [ -z "$TAG_NAME" ]; then + echo "No tags found, using current branch name instead." + TAG_NAME=$(git rev-parse --abbrev-ref HEAD) + fi + # Assume the tag (or branch name) is in the format "branch-something". BRANCH_NAME=$(echo "$TAG_NAME" | cut -d '-' -f1) echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV @@ -37,11 +43,30 @@ jobs: - name: Commit and Push to GitHub Pages run: | + # Configure git git config --global user.name "github-actions" git config --global user.email "github-actions@github.com" - git checkout gh-pages || git checkout --orphan gh-pages - git pull origin gh-pages || true - python .github/scripts/generate_changelog.py --repo_path . --changelog_path ./CHANGELOG-${BRANCH_NAME}.json --branch_name $BRANCH_NAME - git add CHANGELOG-*.json - git commit -m "Update Changelog for $TAG_NAME" - git push origin gh-pages + + # Save the generated changelog file to a temporary directory outside the repo + mkdir -p ../changelog_temp + python .github/scripts/generate_changelog.py --repo_path . --changelog_path ../changelog_temp/CHANGELOG-${BRANCH_NAME}.json --branch_name $BRANCH_NAME + + # Now, checkout the gh-pages branch: + if git show-ref --quiet refs/heads/gh-pages; then + git checkout gh-pages + else + git checkout --orphan gh-pages + # Remove all tracked files if any + git rm -rf . + fi + + # Clean the working directory (removing untracked files) + git clean -fdx + + # Copy back the changelog file from the temporary location + cp ../changelog_temp/CHANGELOG-${BRANCH_NAME}.json . + + # Stage, commit, and push only the changelog file + git add CHANGELOG-${BRANCH_NAME}.json + git commit -m "Update Changelog for $TAG_NAME" || echo "No changes to commit" + git push origin gh-pages --force