From 7ef4a9124a62e29956b576e4f105ba9c21d5a30f Mon Sep 17 00:00:00 2001 From: Samgu Lee Date: Sun, 7 Jun 2026 18:48:41 +0900 Subject: [PATCH] feat: set publishing strategy --- .github/workflows/astro.yml | 5 +- .github/workflows/update-changelog.yml | 86 ++++++++++++++++++++++++++ CHANGELOG.md | 1 + 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/update-changelog.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/astro.yml b/.github/workflows/astro.yml index 6e1b43a..bd4e99f 100644 --- a/.github/workflows/astro.yml +++ b/.github/workflows/astro.yml @@ -5,9 +5,8 @@ name: Deploy Astro site to Pages on: - # Runs on pushes targeting the default branch - push: - branches: ["main"] + release: + types: [published] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..d1be063 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,86 @@ +name: update-changelog + +on: + release: + types: [published] + +jobs: + update: + runs-on: ubuntu-latest + + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # updated CHANGELOG back to the repository. + # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + # Fetch entire history of repository to ensure relase date can be + # extracted from commit of the given tag. + fetch-depth: 0 + # Checkout target branch of this release. Ensures that the CHANGELOG + # is not out of date. + ref: ${{ github.event.release.target_commitish }} + + - name: Check if branch and release match + if: ${{ github.event.release.target_commitish != 'main' && github.event.release.target_commitish != 'master' }} + id: guard + run: | + NUMERIC_VERSION="${RELEASE_TAG_NAME#v}" + MAJOR_VERSION="${NUMERIC_VERSION%%.*}" + BRANCH_MAJOR_VERSION="${BRANCH%%.*}" + + echo "MAJOR_VERSION=$(echo $MAJOR_VERSION)" >> $GITHUB_OUTPUT; + echo "BRANCH_MAJOR_VERSION=$(echo $BRANCH_MAJOR_VERSION)" >> $GITHUB_OUTPUT; + + if [ "$MAJOR_VERSION" != "$BRANCH_MAJOR_VERSION" ]; then + echo "Mismatched versions! Aborting." + VERSION_MISMATCH='true'; + else + echo "Versions match! Proceeding." + VERSION_MISMATCH='false'; + fi + echo "VERSION_MISMATCH=$(echo $VERSION_MISMATCH)" >> $GITHUB_OUTPUT; + env: + BRANCH: ${{ github.event.release.target_commitish }} + RELEASE_TAG_NAME: ${{ github.event.release.tag_name }} + + - name: Fail if branch and release tag do not match + if: ${{ steps.guard.outputs.VERSION_MISMATCH == 'true' }} + uses: actions/github-script@v6 + with: + script: | + core.setFailed('Workflow failed. Release version does not match with selected target branch. Changelog not updated automatically.') + + - name: Extract release date from git tag + id: release_date + run: | + # Get UNIX timestamp from git-tag + TIMESTAMP_OF_RELEASE_COMMIT=$(git log -1 --date=unix --format=%ad '${{ github.event.release.tag_name }}'); + + # Convert timestamp to UTC date in Y-m-d format + FORMATED_DATE=$(date -u -d @$TIMESTAMP_OF_RELEASE_COMMIT +%Y-%m-%d) + + # Make date available to other steps + echo "date=$(echo $FORMATED_DATE)" >> $GITHUB_OUTPUT; + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + # Pass extracted release date, release notes and version to the Action. + release-date: ${{ steps.release_date.outputs.date }} + release-notes: ${{ github.event.release.body }} + latest-version: ${{ github.event.release.tag_name }} + compare-url-target-revision: ${{ github.event.release.target_commitish }} + parse-github-usernames: true + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v6 + with: + # Push updated CHANGELOG to release target branch. + branch: ${{ github.event.release.target_commitish }} + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..38bf0d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# Release Notes