Skip to content

Commit

Permalink
Auto release via GH Actions (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben White <ben@posthog.com>
  • Loading branch information
marandaneto and benjackwhite authored Oct 25, 2023
1 parent bec3aff commit 19064a4
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 27 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Release'
on:
release:
# runs for stable and pre-releases
types: [published]

jobs:
cancel-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@01ce38bf961b4e243a6342cbade0dbc8ba3f0432 # pin@0.12.0
with:
access_token: ${{ github.token }}

release:
name: Release
runs-on: macos-latest
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} # Using Manoel's token for now

steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Install Cocoapods
run: gem install cocoapods

- name: Update version
run: ./scripts/bump-version.sh ${{ github.event.release.tag_name }}

- name: Commit & push
run: |
echo "Tag name from github.ref_name: ${{ github.event.release.target_commitish }}"
./scripts/commit-code.sh ${{ github.event.release.target_commitish }}
- name: Release
run: make releaseCocoaPods
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Next

## 3.0.0-alpha.1

- First alpha of the new major version of the iOS SDK

## 2.1.0 - 2023-10-10

- isFeatureEnabled now returns false if disabled [#74](https://github.com/PostHog/posthog-ios/pull/74)
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build buildSdk buildExample format swiftLint swiftFormat test lint bootstrap
.PHONY: build buildSdk buildExample format swiftLint swiftFormat test lint bootstrap releaseCocoaPods

build: buildSdk buildExample

Expand Down Expand Up @@ -27,3 +27,6 @@ bootstrap:
gem install xcpretty
brew install swiftlint
brew install swiftformat

releaseCocoaPods:
pod trunk push PostHog.podspec --allow-warnings
1 change: 1 addition & 0 deletions PostHog/PostHogVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

import Foundation

// if you change this, make sure to also change it in the podspec and check if the script scripts/bump-version.sh still works
let postHogVersion = "3.0.0-alpha.1"
2 changes: 1 addition & 1 deletion PostHog/Utils/Data+Gzip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

// issues importing scoped classes
//import struct Foundation.Data
// import struct Foundation.Data
import Foundation

#if os(Linux)
Expand Down
2 changes: 1 addition & 1 deletion PostHogTests/PostHogTest.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import Nimble
import Quick
import Foundation

@testable import PostHog

Expand Down
2 changes: 1 addition & 1 deletion PostHogTests/SessionManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Created by Ben White on 22.03.23.
//

import Foundation
import Nimble
@testable import PostHog
import Quick
import Foundation

class SessionManagerTest: QuickSpec {
override func spec() {
Expand Down
2 changes: 1 addition & 1 deletion PostHogTests/StorageTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Created by Ben White on 08.02.23.
//

import Foundation
import Nimble
import Quick
import Foundation

@testable import PostHog

Expand Down
36 changes: 14 additions & 22 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# Releasing

1. Update the version in `PostHog.podspec`, `PostHog/Info.plist`, and `version` in `PostHog/Classes/PHGPostHog.m` to the next release version.
2. Update the `CHANGELOG.md` for the impending release.
3. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version).
4. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version).
5. `git push && git push --tags`.
6. `pod trunk push PostHog.podspec --allow-warnings`.
7. Go to [GH Releases](https://github.com/PostHog/posthog-ios/releases) and create a new release from the tag you just pushed. Copy the changelog entry into the description and publish the release.

## On Apple Silicon

Run this first:

```bash
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install
```

Then, [configure XCode CLI tools](https://stackoverflow.com/questions/29108172/how-do-i-fix-the-xcrun-unable-to-find-simctl-error).

Finally, prepend `arch -x86_64` to the pod command in the steps above.
Releasing
=========

1. Update the CHANGELOG.md with the version and date
2. Go to [GH Releases](https://github.com/PostHog/posthog-ios/releases)
3. Choose a tag name (e.g. `3.0.0`), this is the version number of the release.
1. Preview releases follow the pattern `3.0.0-alpha.1`, `3.0.0-beta.1`, `3.0.0-RC.1`
4. Choose a release name (e.g. `3.0.0`), ideally it matches the above.
5. Write a description of the release.
6. Publish the release.
7. GH Action (release.yml) is doing everything else automatically.
1. SPM uses the tag name to determine the version, directly from the repo.
2. CocoaPods are published.
8. Done.
17 changes: 17 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# ./scripts/bump-version.sh <new version>
# eg ./scripts/bump-version.sh "3.0.0-alpha.1"

set -eux

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_DIR/..

NEW_VERSION="$1"

# Replace `postHogVersion` with the given version
perl -pi -e "s/postHogVersion = \".*\"/postHogVersion = \"$NEW_VERSION\"/" PostHog/PostHogVersion.swift

# Replace `s.version` with the given version
perl -pi -e "s/s.version = \".*\"/s.version = \"$NEW_VERSION\"/" PostHog.podspec
19 changes: 19 additions & 0 deletions scripts/commit-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_DIR/..

GITHUB_BRANCH="${1}"

if [[ $(git status) == *"nothing to commit"* ]]; then
echo "Nothing to commit."
else
echo "Going to push the changes."
git config --global user.name 'PostHog Github Bot'
git config --global user.email 'github-bot@posthog.com'
git fetch
git checkout ${GITHUB_BRANCH}
git commit -am "Update version"
git push --set-upstream origin ${GITHUB_BRANCH}
fi

0 comments on commit 19064a4

Please sign in to comment.