From f12b753e6f8c4737c5e9cbb620bebe19ce733c84 Mon Sep 17 00:00:00 2001 From: Sufien Tout Date: Thu, 19 Dec 2024 10:27:43 -0500 Subject: [PATCH] refactor: combine release and tag creation --- .github/scripts/changelog.sh | 26 ++++++++++++++++++---- .github/scripts/tag.sh | 40 ---------------------------------- .github/workflows/release.yaml | 10 ++++++++- .github/workflows/tag.yaml | 28 ------------------------ 4 files changed, 31 insertions(+), 73 deletions(-) delete mode 100755 .github/scripts/tag.sh delete mode 100644 .github/workflows/tag.yaml diff --git a/.github/scripts/changelog.sh b/.github/scripts/changelog.sh index 196bc038..0094a2be 100755 --- a/.github/scripts/changelog.sh +++ b/.github/scripts/changelog.sh @@ -1,25 +1,26 @@ #!/bin/bash +set -e + release_has_public_changes=false url=$(git remote get-url origin | sed -r 's/(.*)\.git/\1/') - previous_tag=$(git describe --tags --abbrev=0 HEAD~) echo "Changes since $previous_tag:" echo # Loop through all commits since previous tag -for rev in $(git log $previous_tag..HEAD --format="%H" --reverse --no-merges) +for rev in $(git log "$previous_tag"..HEAD --format="%H" --reverse --no-merges) do - summary=$(git log $rev~..$rev --format="%s") + summary=$(git log "$rev"~.."$rev" --format="%s") # Exclude commits starting with "Meta" if [[ $summary != Meta* ]] then # Print markdown list of commit headlines echo "* [$summary]($url/commit/$rev)" # Append commit body indented (blank lines and signoff trailer removed) - git log $rev~..$rev --format="%b" | sed '/^\s*$/d' | sed '/^Signed-off-by:/d' | \ + git log "$rev"~.."$rev" --format="%b" | sed '/^\s*$/d' | sed '/^Signed-off-by:/d' | \ while read -r line do # Escape markdown formatting symbols _ * ` @@ -34,3 +35,20 @@ then echo "No public changes since $previous_tag." >&2 exit 1 fi + +head_tag=$(git describe --exact-match 2>/dev/null || true) + +git log --color=always --format="%C(auto)%h %s%d" | head + +if [[ ${head_tag} =~ [\d{2}\.\d{2}\.\d+] ]]; then + echo "Version tag ${head_tag} already exists." +else + git config --local user.email "github-actions@users.noreply.github.com" + git config --local user.name "github-actions" + version=$(date +'%y.%m.0') + git tag -a "${version}" -m "Release ${version}" + git push origin "${version}" + git log --color=always --format="%C(auto)%h %s%d" | head -1 + echo "Pushed new tag:" + echo "${url}/releases/tag/${version}" +fi diff --git a/.github/scripts/tag.sh b/.github/scripts/tag.sh deleted file mode 100755 index bae420fe..00000000 --- a/.github/scripts/tag.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -set -e - -tag_has_public_changes=false - -previous_tag=$(git describe --tags --abbrev=0 HEAD~) - -# Enable case-insensitive matching -shopt -s nocasematch - -# Loop through all commits since previous tag -for rev in $(git log "$previous_tag"..HEAD --format="%H" --reverse --no-merges); do - summary=$(git log "$rev"~.."$rev" --format="%s") - # Exclude commits starting with "Meta" - if [[ $summary != Meta* ]]; then - tag_has_public_changes=true - break - fi -done - -head_tag=$(git describe --exact-match 2>/dev/null || true) - -git log --color=always --format="%C(auto)%h %s%d" | head - -if ! $tag_has_public_changes; then - echo "No public changes since $previous_tag." >&2 - exit 1 -elif [[ ${head_tag} =~ [\d{2}\.\d{2}\.\d+] ]]; then - echo "Version tag ${head_tag} already exists." -else - git config --local user.email "github-actions@users.noreply.github.com" - git config --local user.name "github-actions" - version=$(date +'%y.%m.0') - git tag -a ${version} -m "Release ${version}" - git push origin ${version} - git log --color=always --format="%C(auto)%h %s%d" | head -1 - echo "Pushed new tag:" - echo "${REPO_URL}/releases/tag/${version}" -fi diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a88dfc35..001597de 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,13 +15,21 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + # The COMMIT_KEY secret contains a private SSH key. The associated public key + # has been added as a deploy key in the GitHub project. See: + # https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys + # This is necessary to make commits done by github-actions able to trigger + # further github-actions. See: https://stackoverflow.com/q/60418323/3018229. + ssh-key: "${{secrets.COMMIT_KEY}}" - name: Create Package run: tar -czf forgit-${{github.ref_name}}.tar.gz --exclude LICENSE --exclude README.md * - - name: Generate Changelog + - name: Generate Changelog and Tag id: changelog run: .github/scripts/changelog.sh > CHANGELOG.md + env: + REPO_URL: ${{github.server_url}}/${{github.repository}} continue-on-error: true - name: Release diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml deleted file mode 100644 index 4cf5a27e..00000000 --- a/.github/workflows/tag.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Tag - -on: - schedule: - # Run on every first day of the month - - cron: '0 0 1 * *' - -jobs: - - tag: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - # The COMMIT_KEY secret contains a private SSH key. The associated public key - # has been added as a deploy key in the GitHub project. See: - # https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys - # This is necessary to make commits done by github-actions able to trigger - # further github-actions. See: https://stackoverflow.com/q/60418323/3018229. - ssh-key: "${{secrets.COMMIT_KEY}}" - - - name: Create Tag - run: .github/scripts/tag.sh - env: - REPO_URL: ${{github.server_url}}/${{github.repository}}