Skip to content

Commit

Permalink
Merge pull request #600 from arabcoders/dev
Browse files Browse the repository at this point in the history
more github workflow updates
  • Loading branch information
arabcoders authored Feb 3, 2025
2 parents 2ef4083 + 8ea02be commit 74e3822
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 110 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF" >> "$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 }}
81 changes: 0 additions & 81 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF" >> "$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 }}
43 changes: 32 additions & 11 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,44 @@ 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
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: |
# 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
mv CHANGELOG-*.json .
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
41 changes: 23 additions & 18 deletions frontend/pages/changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@
</div>
</div>
</div>
<div class="column is-12" v-for="log in logs" :key="log.tag">
<h1 class="is-4">
<span class="icon-text">
<span class="icon"><i class="fas fa-code-branch"></i></span>
<span>
{{ log.tag }} <span class="subtitle" v-if="log.tag === api_version">Installed</span>
<div class="column is-12" v-for="(log, index) in logs" :key="log.tag">
<div class="content">
<h1 class="is-4">
<span class="icon-text">
<span class="icon"><i class="fas fa-code-branch"></i></span>
<span>
{{ log.tag }} <span class="subtitle" v-if="log.tag === api_version">Installed</span>
</span>
</span>
</span>
</h1>
<ul>
<li v-for="commit in log.commits" :key="commit.sha">
<p>
<strong>{{ commit.message }}</strong>
<br>
<small>{{ commit.sha }} - {{ moment(commit.date).fromNow() }}</small>
</p>
</li>
</ul>
</h1>
<hr>
<ul>
<li v-for="commit in log.commits" :key="commit.sha">
<strong>{{ ucFirst(commit.message).replace(/\.$/, "") }}.</strong> -
<small>
<span class="has-tooltip" v-tooltip="`Date: ${commit.date}`">
{{ moment(commit.date).fromNow() }}
</span></small>
</li>
</ul>
<hr v-if="index < logs.length - 1">
</div>
</div>
</div>
</template>
Expand All @@ -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 () => {
Expand Down

0 comments on commit 74e3822

Please sign in to comment.