A. Release: flutter_inapp_purchase #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Release: flutter_inapp_purchase" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version bump type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - current | |
| - rc-bump | |
| default: patch | |
| prerelease: | |
| description: "Publish as prerelease (-rc.1)" | |
| required: false | |
| default: false | |
| type: boolean | |
| create_release: | |
| description: "Also create a GitHub Release" | |
| required: false | |
| default: true | |
| type: boolean | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| deploy: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: libraries/flutter_inapp_purchase | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.DEPENDENCY_UPDATE_PAT }} | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| channel: "stable" | |
| flutter-version: "3.x" | |
| - name: Install dependencies | |
| run: flutter pub get | |
| - name: Lint | |
| run: flutter analyze | |
| - name: Test | |
| run: flutter test | |
| - name: Configure Git user | |
| run: | | |
| git config user.name "flutter-iap bot" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Calculate version | |
| id: bump | |
| run: | | |
| VERSION_TYPE="${{ inputs.version }}" | |
| IS_PRERELEASE="${{ inputs.prerelease }}" | |
| CURRENT_VERSION=$(awk '/^version:/{print $2; exit}' pubspec.yaml) | |
| if [ "$VERSION_TYPE" = "current" ]; then | |
| NEW_VERSION="$CURRENT_VERSION" | |
| echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "prev_version=${CURRENT_VERSION%%[-+]*}" >> "$GITHUB_OUTPUT" | |
| if [[ "$NEW_VERSION" == *-* ]]; then | |
| echo "is_prerelease=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_prerelease=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| exit 0 | |
| fi | |
| BASE_VERSION="${CURRENT_VERSION%%[-+]*}" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION" | |
| if [ "$VERSION_TYPE" = "rc-bump" ]; then | |
| RC_NUM=$(echo "$CURRENT_VERSION" | sed -n 's/.*-rc\.\([0-9]*\)/\1/p') | |
| if [ -z "$RC_NUM" ]; then | |
| echo "::error::Current version $CURRENT_VERSION is not an rc version." | |
| exit 1 | |
| fi | |
| NEW_VERSION="${BASE_VERSION}-rc.$((RC_NUM + 1))" | |
| elif [ "$IS_PRERELEASE" = "true" ]; then | |
| # major/minor/patch + prerelease → X.Y.Z-rc.1 | |
| case "$VERSION_TYPE" in | |
| major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; | |
| minor) MINOR=$((MINOR + 1)); PATCH=0 ;; | |
| patch) PATCH=$((PATCH + 1)) ;; | |
| esac | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-rc.1" | |
| else | |
| # Stable release — if current version is RC, strip prerelease without bumping | |
| IS_RC=$(echo "$CURRENT_VERSION" | grep -c '\-rc\.' || true) | |
| if [ "$IS_RC" -gt 0 ] && [ "$VERSION_TYPE" = "patch" ]; then | |
| NEW_VERSION="${BASE_VERSION}" | |
| else | |
| case "$VERSION_TYPE" in | |
| major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; | |
| minor) MINOR=$((MINOR + 1)); PATCH=0 ;; | |
| patch) PATCH=$((PATCH + 1)) ;; | |
| esac | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| fi | |
| fi | |
| sed -i "s/^version: .*/version: ${NEW_VERSION}/" pubspec.yaml | |
| echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "prev_version=$BASE_VERSION" >> "$GITHUB_OUTPUT" | |
| if [[ "$NEW_VERSION" == *-* ]]; then | |
| echo "is_prerelease=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_prerelease=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Generate CHANGELOG entry | |
| if: ${{ inputs.version != 'current' }} | |
| env: | |
| NEW_VERSION: ${{ steps.bump.outputs.version }} | |
| PREV_VERSION: ${{ steps.bump.outputs.prev_version }} | |
| run: | | |
| DATE=$(date +%Y-%m-%d) | |
| CHANGES="" | |
| if git rev-parse "$PREV_VERSION" >/dev/null 2>&1; then | |
| PR_LINES=$(git log "${PREV_VERSION}..HEAD" --merges --pretty=format:"%s" | \ | |
| sed -n 's/^Merge pull request #\([0-9]*\) from .*/\1/p') | |
| for PR_NUM in $PR_LINES; do | |
| PR_TITLE=$(git log --all --grep="Merge pull request #${PR_NUM}" --pretty=format:"%s" | head -1 | sed "s|Merge pull request #${PR_NUM} from [^ ]* ||") | |
| if [ -n "$PR_TITLE" ]; then | |
| CHANGES="${CHANGES}- ${PR_TITLE} (#${PR_NUM})\n" | |
| fi | |
| done | |
| if [ -z "$CHANGES" ]; then | |
| CHANGES=$(git log "${PREV_VERSION}..HEAD" --no-merges --pretty=format:"- %s" | head -20) | |
| CHANGES="${CHANGES}\n" | |
| fi | |
| else | |
| CHANGES="- Initial release\n" | |
| fi | |
| ENTRY="## ${NEW_VERSION} (${DATE})\n\n${CHANGES}" | |
| if [ -f CHANGELOG.md ]; then | |
| EXISTING=$(cat CHANGELOG.md) | |
| printf "%b" "# Changelog\n\n${ENTRY}\n${EXISTING#"# Changelog"*$'\n'}" > CHANGELOG.md | |
| else | |
| printf "%b" "# Changelog\n\n${ENTRY}" > CHANGELOG.md | |
| fi | |
| - name: Commit and tag | |
| if: ${{ inputs.version != 'current' }} | |
| env: | |
| NEW_VERSION: ${{ steps.bump.outputs.version }} | |
| run: | | |
| git add pubspec.yaml | |
| [ -f CHANGELOG.md ] && git add CHANGELOG.md | |
| git commit -m "chore(release): flutter_inapp_purchase ${NEW_VERSION}" | |
| git tag "flutter-iap-${NEW_VERSION}" | |
| - name: Tag only (current version) | |
| if: ${{ inputs.version == 'current' }} | |
| env: | |
| NEW_VERSION: ${{ steps.bump.outputs.version }} | |
| run: | | |
| git tag -f "flutter-iap-${NEW_VERSION}" | |
| - name: Push commit and tags | |
| if: ${{ inputs.version != 'current' }} | |
| run: | | |
| git stash --include-untracked || true | |
| git pull --rebase origin main | |
| git stash pop || true | |
| git push --follow-tags | |
| - name: Push tag (current version) | |
| if: ${{ inputs.version == 'current' }} | |
| env: | |
| NEW_VERSION: ${{ steps.bump.outputs.version }} | |
| run: | | |
| git push origin "flutter-iap-${NEW_VERSION}" --force | |
| - name: Create GitHub Release | |
| if: ${{ inputs.create_release }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: flutter-iap-${{ steps.bump.outputs.version }} | |
| name: flutter_inapp_purchase ${{ steps.bump.outputs.version }} | |
| draft: false | |
| prerelease: ${{ steps.bump.outputs.is_prerelease }} | |
| generate_release_notes: true |