GitHub actions #7
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: | |
dry-run: | |
runs-on: ubuntu-latest | |
name: Flutter Pub Publish --dry-run | |
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: Run flutter pub publish --dry-run | |
run: flutter pub publish --dry-run | |
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: Stash changes | |
run: git reset --hard | |
- 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: 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 = '$NEW_VERSION'/" ios/hypersdkflutter.podspec | |
# Commit the updated pubspec.yaml file | |
git add pubspec.yaml | |
git add ios/hypersdkflutter.podspec | |
git commit -m "chore: bump version to ${{ env.new_version }}" | |
shell: bash | |
- name: Tag the new version | |
run: | | |
git tag "v${{ env.new_version }}" | |
git push origin "v${{ env.new_version }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to pub.dev | |
uses: k-paxian/[email protected] | |
with: | |
credentialJson: ${{ secrets.PUB_PUBLISH_TOKEN }} | |
flutter: true | |
skipTests: true |