Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflows #1

Merged
merged 13 commits into from
Sep 11, 2023
39 changes: 39 additions & 0 deletions .github/workflows/complete-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Complete Release

on:
pull_request:
types:
- closed
branches:
- main

jobs:
tag-and-release:
# Run only after release PR branch is merged
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'releases/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get Tag Name
id: get_tag_name
run: echo "tag_name=v$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT

- name: Create Tag
id: create_tag
uses: rickstaa/action-create-tag@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.get_tag_name.outputs.tag_name }}

- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag_name.outputs.tag_name }}
name: ${{ steps.get_tag_name.outputs.tag_name }}
draft: false
prerelease: false
body_path: .scripts/changes.md
67 changes: 67 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Prepare Release

on:
workflow_dispatch:
inputs:
distribution-version:
description: 'Distribution Version of the release'
default: 'patch'
required: true
type: string

jobs:
update-native-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: master

- name: Update version in package.json
id: version
run: |
npm version ${{ inputs.distribution-version }} --no-git-tag-version
echo "version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT

- name: Update incidental copies of distribution version
run: .scripts/update_distribution_version.sh "${{ steps.version.outputs.version }}"

- name: Get version from latest CocoaPods release of ApptentiveKit iOS
id: ios-version
run: |
IOS_VERSION=$(curl -s "https://cocoapods.org/pods/ApptentiveKit" | sed -n 's/.*<h1>ApptentiveKit <span>\([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*/\1/p')
echo "ios_version=$IOS_VERSION" >> $GITHUB_OUTPUT

- name: Update ApptentiveKit iOS dependency
run: .scripts/update_ios_version.sh apptentive-react-native.podspec "${{ steps.ios-version.outputs.ios_version }}"

- name: Get version from latest Maven release of ApptentiveKit Android
id: android-version
run: echo "android_version=$(curl -s 'https://search.maven.org/solrsearch/select?q=g:com.apptentive+AND+a:apptentive-kit-android&wt=json' | jq -r '.response.docs[0].latestVersion')" >> $GITHUB_OUTPUT

- name: Update ApptentiveKit Android dependency
run: .scripts/update_android_version.sh android/build.gradle "${{ steps.android-version.outputs.android_version }}"

- name: Check version numbers
uses: actions/github-script@v4
with:
script: |
if( "${{steps.version.outputs.version}}" == "" || "${{steps.ios-version.outputs.ios_version}}" == "" || "${{steps.android-version.outputs.android_version}}" == "" ){
core.setFailed('One or more version numbers are empty.')
}

- name: Update CHANGELOG.md
id: changelog
run: |
.scripts/add_changelog_entry.sh "${{ steps.version.outputs.version }}" "${{ steps.android-version.outputs.android_version }}" "${{ steps.ios-version.outputs.ios_version }}" \
> .scripts/changes.md

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: "Release ${{ steps.version.outputs.version }}"
committer: "Alchemer Mobile Team <sdks@apptentive.com>"
branch: "releases/${{ steps.version.outputs.version }}"
base: master
title: "Release ${{ steps.version.outputs.version }}"
body-path: .scripts/changes.md
46 changes: 46 additions & 0 deletions .scripts/add_changelog_entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Fail on first error.
set -e

# Check for correct number of arguments.
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <new.distribution.version> <new.ios.version> <new.android.version>"
exit 1 # Exit the script with an error status
fi

# Create and change to a temporary directory.
mkdir CHANGELOG-update
cd CHANGELOG-update

# Split the CHANGELOG.md file into multiple parts with a pattern matching
# the start of a new version entry.
# The filenames with be 'xaa', 'xab', 'xac', etc.
cat ../CHANGELOG.md | csplit -s - '/^# 20/' {1}

# Create the new version entry's heading and add it to a file whose name
# is alphabetically after the CHANGELOG's preamble.
echo "# $(date -Idate) - v$1" > xx00a
echo "" >> xx00a

# Add the new version entry's body a file whose name is alphabetically
# after the heading.
echo "- Apptentive Android SDK: $2" > xx00b
echo "- Apptentive iOS SDK: $3" >> xx00b
echo "" >> xx00b

# Copy the new entry to print out later.
NEW_ENTRY=$(cat xx00b)

# Reassebmble the parts of the changelog into a local copy.
cat $(ls -1 | sort) > foo.md

# Move the local copy of the changelog to the original location.
mv foo.md ../CHANGELOG.md

# Clean up the temporary directory.
rm x*
cd ..
rmdir CHANGELOG-update

echo "$NEW_ENTRY"
2 changes: 2 additions & 0 deletions .scripts/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Apptentive Android SDK: 6.1.0
- Apptentive iOS SDK: 6.2.2
25 changes: 25 additions & 0 deletions .scripts/update_android_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Fail on first error.
set -e

# Check for correct number of arguments.
if [ $# -ne 2 ]; then
echo "Usage: $0 <build.gradle_filename> <new.apptentive-kit-android.version>"
exit 1
fi

dependency_name="com.apptentive:apptentive-kit-android"
new_version="$2"
build_gradle_file="$1"

# Check if the build.gradle file exists
if [ ! -f "$build_gradle_file" ]; then
echo "Error: $build_gradle_file does not exist."
exit 1
fi

# Use sed to update the version in the podspec file
sed -i "s/implementation '$dependency_name:[^']*'/implementation '$dependency_name:$new_version'/" "$build_gradle_file"

echo "Updated $dependency_name to version $new_version in $build_gradle_file."
16 changes: 16 additions & 0 deletions .scripts/update_distribution_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# This script should update any incidental copies of the
# "single source of truth" version, e.g. in package.json.
# It will be different for each project.

# Fail on first error.
set -e

# Check for correct number of arguments.
if [ $# -ne 1 ]; then
echo "Usage: $0 <new.distribution.version>"
exit 1
fi

echo "No files need version updates ($new_version)."
25 changes: 25 additions & 0 deletions .scripts/update_ios_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Fail on first error.
set -e

# Check for correct number of arguments.
if [ $# -ne 2 ]; then
echo "Usage: $0 <podspec_filename> <new.ApptentiveKit.version>"
exit 1
fi

dependency_name="ApptentiveKit"
new_version="$2"
podspec_file="$1"

# Check if the podspec file exists
if [ ! -f "$podspec_file" ]; then
echo "Error: $podspec_file does not exist."
exit 1
fi

# Use sed to update the version in the podspec file
sed -i "s/s.dependency '$dependency_name', '[^']*'/s.dependency '$dependency_name', '$new_version'/" "$podspec_file"

echo "Updated $dependency_name to version $new_version in $podspec_file."
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This document lets you know what has changed in the React Native module. For cha
- [Android Changelog](https://github.com/apptentive/apptentive-kit-android/blob/master/CHANGELOG.md)
- [iOS Changelog](https://github.com/apptentive/apptentive-kit-ios/blob/main/CHANGELOG.md)

# 2023-08-02 - v6.1.3

- Apptentive Android SDK: 6.1.0
- Apptentive iOS SDK: 6.2.2

# 2023-04-26 - v6.1.2

- Apptentive Android SDK: 6.0.4
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

// Apptentive
implementation 'com.apptentive:apptentive-kit-android:6.0.4'
implementation 'com.apptentive:apptentive-kit-android:6.1.0'
}

if (isNewArchitectureEnabled()) {
Expand Down
Loading
Loading