diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 896b484a0..48bc32e0b 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -1,8 +1,8 @@ -name: Release Drafter +name: Release on: workflow_dispatch: schedule: - - cron: '0 0 1-7 * 1' # First Monday of every month at midnight UTC + - cron: '0 0 1-7 * 3' # First Wednesday of every month at midnight UTC permissions: contents: write @@ -12,11 +12,19 @@ jobs: runs-on: ubuntu-latest steps: + - name: Generate GitHub App token + id: app_token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + - name: Checkout uses: actions/checkout@v6 with: ref: master fetch-depth: 0 # full history needed for git log/tags + token: ${{ steps.app_token.outputs.token }} - name: Get latest tag id: latest_tag @@ -49,25 +57,46 @@ jobs: OA_VERSION=$(jq -r '.oaVersion' package.json) PREBID_VERSION=$(jq -r '.version' package.json) - # Increment minor version (major.minor.patch → major.(minor+1).patch) MAJOR=$(echo "$OA_VERSION" | cut -d. -f1) MINOR=$(echo "$OA_VERSION" | cut -d. -f2) PATCH=$(echo "$OA_VERSION" | cut -d. -f3) - NEW_MINOR=$((MINOR + 1)) - NEW_OA_VERSION="${MAJOR}.${NEW_MINOR}.${PATCH}" - # Write new version back to package.json - jq --arg v "$NEW_OA_VERSION" '.oaVersion = $v' package.json > package.tmp.json - mv package.tmp.json package.json + # Check if oaVersion differs between master and the last tagged commit + TAG="${{ steps.latest_tag.outputs.tag }}" + if [ -n "$TAG" ]; then + TAGGED_OA_VERSION=$(git show "$TAG":package.json | jq -r '.oaVersion') + echo "oaVersion on master: $OA_VERSION" + echo "oaVersion on last tag ($TAG): $TAGGED_OA_VERSION" + fi + + if [ -n "$TAG" ] && [ "$OA_VERSION" != "$TAGGED_OA_VERSION" ]; then + echo "oaVersion has been manually changed since last tag — skipping minor increment." + NEW_OA_VERSION="$OA_VERSION" + + echo "version_bumped=false" >> $GITHUB_OUTPUT + else + echo "oaVersion unchanged since last tag — incrementing minor." + NEW_MINOR=$((MINOR + 1)) + NEW_OA_VERSION="${MAJOR}.${NEW_MINOR}.${PATCH}" + + # Write new version back to package.json + jq --arg v "$NEW_OA_VERSION" '.oaVersion = $v' package.json > package.tmp.json + mv package.tmp.json package.json + + echo "version_bumped=true" >> $GITHUB_OUTPUT + fi echo "oa_version=$NEW_OA_VERSION" >> $GITHUB_OUTPUT echo "prebid_version=$PREBID_VERSION" >> $GITHUB_OUTPUT - name: Commit incremented OA version - if: steps.changes.outputs.has_changes == 'true' + if: steps.changes.outputs.has_changes == 'true' && steps.versions.outputs.version_bumped == 'true' + env: + GH_TOKEN: ${{ steps.app_token.outputs.token }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" + git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" git add package.json git commit -m "chore: bump OpenAds version to ${{ steps.versions.outputs.oa_version }}" git push origin HEAD:master @@ -78,7 +107,7 @@ jobs: if: steps.changes.outputs.has_changes == 'true' id: commits env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ steps.app_token.outputs.token }} run: | TAG="${{ steps.latest_tag.outputs.tag }}" REPO="${{ github.repository }}" @@ -89,48 +118,43 @@ jobs: RANGE="$TAG..HEAD" fi - # Collect commits: " " LINES="" - while IFS= read -r line; do - SHA=$(echo "$line" | awk '{print $1}') - SUBJECT=$(echo "$line" | cut -d' ' -f2-) - # Try to extract a PR number from the commit subject, e.g. "(#123)" - PR_NUM=$(echo "$SUBJECT" | grep -oP '#\K[0-9]+' | head -1) + while IFS= read -r -d $'\x00' commit; do + TITLE=$(echo "$commit" | awk -F'|SEP|' '{print $2}' | xargs -0| sed '/^$/d' | sed 's/^[[:space:]]*//') + + # Try to extract a PR number from the title, e.g. "#123" + PR_NUM=$(echo "$TITLE" | grep -oP '#\K[0-9]+' | head -1) if [ -n "$PR_NUM" ]; then + # Remove the PR reference like "(#123)" from the title + BODY=$(echo "$TITLE" | sed "s/ *(#${PR_NUM}) *|//" | cut -c2-) PR_URL="https://github.com/$REPO/pull/$PR_NUM" - ENTRY="- [#${PR_NUM}](${PR_URL}) ${SUBJECT}" - else - SHORT_SHA="${SHA:0:7}" - COMMIT_URL="https://github.com/$REPO/commit/$SHA" - ENTRY="- [${SHORT_SHA}](${COMMIT_URL}) ${SUBJECT}" + ENTRY="- [#${PR_NUM}](${PR_URL}) ${BODY}" + LINES="${LINES}${ENTRY}"$'\n' fi - LINES="${LINES}${ENTRY}"$'\n' - done < <(git log "$RANGE" --pretty=format:"%H %s") + done < <(git log "$RANGE" --pretty=format:"%H|SEP|%s|SEP|%b%x00") - # Write to a file to safely pass multiline content echo "$LINES" > /tmp/commit_list.txt cat /tmp/commit_list.txt - name: Create GitHub Release if: steps.changes.outputs.has_changes == 'true' env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ steps.app_token.outputs.token }} run: | OA_VERSION="${{ steps.versions.outputs.oa_version }}" PREBID_VERSION="${{ steps.versions.outputs.prebid_version }}" COMMIT_LIST=$(cat /tmp/commit_list.txt) { - echo "Including Prebid features up to v${PREBID_VERSION}: https://github.com/prebid/Prebid.js/releases/tag/${PREBID_VERSION}" + echo "Including Prebid features up to [v${PREBID_VERSION}](https://github.com/prebid/Prebid.js/releases/tag/${PREBID_VERSION})" echo "" echo "OpenAdsJs Changes" echo "${COMMIT_LIST}" } > /tmp/release_notes.md - gh release create "v${OA_VERSION}" \ - --title "OpenAds ${OA_VERSION}" \ - --notes-file /tmp/release_notes.md \ - --target "oajs_v${{ steps.versions.outputs.oa_version }}" \ No newline at end of file + gh release create "oajs_v${OA_VERSION}" \ + --title "OpenAdsJs v${OA_VERSION}" \ + --notes-file /tmp/release_notes.md \ No newline at end of file