fix: Fixed issue github workflow #13
Workflow file for this run
This file contains 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: Publish hypersdkflutter to pub.dev | |
on: | |
pull_request_target: | |
branches: | |
- main | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
types: | |
- closed | |
permissions: | |
contents: write | |
jobs: | |
publish: | |
if: (github.event.pull_request.merged == true && !contains(github.event.pull_request.title, '[skip ci]')) || github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
name: Publish Package to Pub.dev | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: '3.13.0' | |
- name: Install dependencies | |
run: flutter pub get | |
- name: Determine release type | |
id: determine-release | |
run: | | |
shopt -s nocasematch | |
# Determine release type based on pull request title | |
if [[ "${{ github.event.pull_request.title }}" =~ (\[breaking\]|\[major\]) ]]; then | |
echo "release_type=major" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.event.pull_request.title }}" =~ \[minor\] ]]; then | |
echo "release_type=minor" >> $GITHUB_OUTPUT | |
else | |
echo "release_type=patch" >> $GITHUB_OUTPUT | |
fi | |
shopt -u nocasematch | |
shell: bash | |
- name: Generate new version | |
id: new_version | |
run: | | |
# Get the current version from pubspec.yaml | |
CURRENT_VERSION=$(grep 'version: ' pubspec.yaml | sed 's/version: //;s/+.*//') | |
echo "Current version is: $CURRENT_VERSION" | |
# Split the current version into major, minor, and patch | |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" | |
echo "major : $major" | |
echo "minor : $minor" | |
echo "patch : $patch" | |
# Check if the version parts are valid | |
if [[ -z "$major" || -z "$minor" || -z "$patch" ]]; then | |
echo "Invalid version format: $CURRENT_VERSION" | |
exit 1 | |
fi | |
# Determine the release type (major, minor, or patch) based on PR title | |
RELEASE_TYPE="${{ steps.determine-release.outputs.release_type }}" | |
if [[ "$RELEASE_TYPE" == "major" ]]; then | |
NEW_MAJOR=$((major + 1)) | |
NEW_MINOR=0 | |
NEW_PATCH=0 | |
NEW_VERSION="$NEW_MAJOR.0.0" | |
elif [[ "$RELEASE_TYPE" == "minor" ]]; then | |
NEW_MINOR=$((minor + 1)) | |
NEW_PATCH=0 | |
NEW_VERSION="$major.$NEW_MINOR.0" | |
else | |
NEW_PATCH=$((patch + 1)) | |
NEW_VERSION="$major.$minor.$NEW_PATCH" | |
fi | |
echo "New version will be: $NEW_VERSION" | |
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV | |
shell: bash | |
- name: git config | |
run: | | |
git config --local user.name 'hyper-sdk-app[bot]' | |
git config --local user.email '163947841+hyper-sdk-app[bot]@users.noreply.github.com' | |
- name: Stash changes | |
run: git reset --hard | |
- name: Get changelog | |
id: changelog | |
run: echo "commit_message=$(git log -1 --pretty=%B)" >> $GITHUB_ENV | |
- name: Update version in pubspec.yaml | |
run: | | |
# Update the version in pubspec.yaml | |
sed -i "s/^version: .*/version: ${{ env.new_version }}/" pubspec.yaml | |
sed -i "s/s.version[ ]*=[ ]*'.*'/s.version = '${{ env.new_version }}'/g" ios/hypersdkflutter.podspec | |
sed -i "1s/^/# ${{ env.new_version }}\n* ${{ env.commit_message }}\n\n/" CHANGELOG.md | |
# Commit the updated pubspec.yaml file | |
git add pubspec.yaml | |
git add ios/hypersdkflutter.podspec | |
git add CHANGELOG.md | |
git commit -m "chore: bump version to ${{ env.new_version }}" | |
shell: bash | |
- name: Publish to pub.dev | |
uses: k-paxian/[email protected] | |
with: | |
credentialJson: ${{ secrets.PUB_PUBLISH_TOKEN }} | |
flutter: true | |
skipTests: true | |
- name: Create tag for new version | |
run: | | |
git tag "v${{ env.new_version }}" | |
git push origin "v${{ env.new_version }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push release commit | |
run: | | |
git push origin main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
shell: bash |