Skip to content

Commit

Permalink
Merge branch 'main' into mob/implement-discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeblahblah committed Feb 21, 2024
2 parents bb0d332 + 70015f6 commit 665d901
Show file tree
Hide file tree
Showing 10 changed files with 6,191 additions and 340 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
3 changes: 2 additions & 1 deletion .github/actions/generate-native-package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ runs:
args:
- ${{ inputs.access_token }}
- ${{ inputs.platform }}
- ${{ inputs.release_type }}
- ${{ inputs.release_type }}
- ${{ inputs.version }}
16 changes: 8 additions & 8 deletions .github/actions/generate-native-package/native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export ACCESS_TOKEN=$1
export PLATFORM=$2
export RELEASE_TYPE=$3
export VERSION=$4

if [ -z "$RELEASE_TYPE" ] || ! [[ "$RELEASE_TYPE" =~ ^(pre)?release$ ]];
then
Expand All @@ -22,16 +23,15 @@ git clone https://github.com/guardian/bridget.git

cd bridget
git checkout $GITHUB_REF
CURRENT_VERSION="$(git describe --tags --abbrev=0)"
# Add a -branch suffix so the prerelease tag and branch do not have the same name
PRERELEASE_BRANCH_NAME="$CURRENT_VERSION-branch"
PRERELEASE_BRANCH_NAME="$VERSION-branch"
cd ../

# Add version const to thrift file
echo "" >> bridget/thrift/native.thrift
echo "const string BRIDGET_VERSION = \"$CURRENT_VERSION\"" >> bridget/thrift/native.thrift
echo "const string BRIDGET_VERSION = \"$VERSION\"" >> bridget/thrift/native.thrift

echo "Publishing $RELEASE_TYPE to platform $PLATFORM with version $CURRENT_VERSION"
echo "Publishing $RELEASE_TYPE to platform $PLATFORM with version $VERSION"
# Platform tasks
if [ "$PLATFORM" == "ios" ]; then

Expand All @@ -54,14 +54,14 @@ if [ "$PLATFORM" == "ios" ]; then
cd bridget-swift
if [[ -n `git diff` ]]; then
git add Sources/Bridget/*.swift
git commit -m "Update Swift models $CURRENT_VERSION"
git commit -m "Update Swift models $VERSION"
if [ "$RELEASE_TYPE" = "prerelease" ];
then
git push -u origin $PRERELEASE_BRANCH_NAME
else
git push origin main
fi
git tag $CURRENT_VERSION
git tag $VERSION
git push --tags
fi
elif [ "$PLATFORM" == "android" ]; then
Expand Down Expand Up @@ -94,14 +94,14 @@ elif [ "$PLATFORM" == "android" ]; then
cd bridget-android
if [[ -n `git diff` ]]; then
git add library/src/main/*
git commit -m "Update Thrift generated classes $CURRENT_VERSION"
git commit -m "Update Thrift generated classes $VERSION"
if [ "$RELEASE_TYPE" = "prerelease" ];
then
git push -u origin $PRERELEASE_BRANCH_NAME
else
git push origin main
fi
git tag $CURRENT_VERSION
git tag $VERSION
git push --tags
fi
else
Expand Down
56 changes: 0 additions & 56 deletions .github/workflows/generate-packages.yml

This file was deleted.

25 changes: 24 additions & 1 deletion .github/workflows/generate-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,43 @@ permissions:
contents: write

jobs:
get_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_step.outputs.version }}
steps:
- uses: actions/checkout@v4

- name: Version from latest tag
id: version_step
run: |
VERSION=$(git describe --tags --abbrev=0)
echo $VERSION
echo "version=$VERSION" >> $GITHUB_OUTPUT
generate-typescript-package:
needs: get_version
if: "github.event.release.prerelease"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
cache: "npm"
node-version-file: ".nvmrc"

- name: install
run: npm install

- name: generate and publish
run: ./gen-typescript.sh prerelease
run: ./gen-typescript.sh prerelease ${VERSION}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ needs.get_version.outputs.version }}

generate-swift-package:
needs: get_version
runs-on: ubuntu-latest
if: "github.event.release.prerelease"
steps:
Expand All @@ -32,8 +52,10 @@ jobs:
access_token: ${{ secrets.ACCESS_TOKEN }}
platform: "ios"
release_type: "prerelease"
version: ${{ needs.get_version.outputs.version }}

generate-android-package:
needs: get_version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -42,3 +64,4 @@ jobs:
access_token: ${{ secrets.ACCESS_TOKEN }}
platform: "android"
release_type: "prerelease"
version: ${{ needs.get_version.outputs.version }}
78 changes: 78 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Create release PR or Release Packages

on:
push:
branches:
- main

jobs:
manage_release:
name: Create release PR or Release Packages
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
# Get the latest 2 commits so we can compare the versions in package.json
fetch-depth: 2

- name: Setup Node
uses: actions/setup-node@v4
with:
cache: "npm"
node-version-file: ".nvmrc"

- name: Check if package version has changed
id: version_check
# Check if the version has changed between this commit's package.json and the previous commit's package.json
run: |
PREV_VERSION=$(git checkout -q HEAD^ && npm pkg get version && git switch -q -)
CURR_VERSION=$(npm pkg get version)
echo "versionChanged=$(if [ "$PREV_VERSION" = "$CURR_VERSION" ]; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT
echo "version=$(echo $CURR_VERSION | xargs)" >> $GITHUB_OUTPUT
- run: npm install

- name: Create Release Pull Request
uses: changesets/action@v1
id: changesets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# The steps below here only run when there's something to publish

- name: Publish NPM
if: steps.changesets.outputs.hasChangesets == 'false' && steps.version_check.outputs.versionChanged == 'true'
run: ./gen-typescript.sh release ${VERSION}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.version_check.outputs.version }}

- name: Publish Android
if: steps.changesets.outputs.hasChangesets == 'false' && steps.version_check.outputs.versionChanged == 'true'
uses: ./.github/actions/generate-native-package
with:
access_token: ${{ secrets.ACCESS_TOKEN }}
platform: "android"
release_type: "release"
version: ${{ steps.version_check.outputs.version }}

- name: Publish iOS
if: steps.changesets.outputs.hasChangesets == 'false' && steps.version_check.outputs.versionChanged == 'true'
uses: ./.github/actions/generate-native-package
with:
access_token: ${{ secrets.ACCESS_TOKEN }}
platform: "ios"
release_type: "release"
version: ${{ steps.version_check.outputs.version }}

- name: Create release in GitHub
uses: changesets/action@v1
if: steps.changesets.outputs.hasChangesets == 'false' && steps.version_check.outputs.versionChanged == 'true'
with:
# We've already published above, but changesets needs this command to exit successfully to create the release in GitHub
publish: node -e true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 11 additions & 8 deletions gen-typescript.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
RELEASE_TYPE=$1
VERSION=$2

if [ -z "$RELEASE_TYPE" ] || ! [[ "$RELEASE_TYPE" =~ ^(pre)?release$ ]];
then
echo "Please specify a release type: prerelease or release";
echo "e.g gen-typescript.sh prerelease";
echo "Please specify a release type as the 1st argument: prerelease or release";
exit 1
fi

if [ -z "$VERSION" ];
then
echo "Please specify a version as the 2nd argument"
exit 1
fi

Expand All @@ -25,17 +31,14 @@ echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
# remove TypeScript files
ls | grep "^[A-Za-z]*.ts" | xargs rm

# use repo tag for version
CURRENT_FULL_VERSION="$(git describe --tags --abbrev=0)"

# publish to npm
npm version ${CURRENT_FULL_VERSION}
npm version ${VERSION}

if [ "$RELEASE_TYPE" = "prerelease" ];
then
echo "Publishing prerelease with version $CURRENT_FULL_VERSION"
echo "Publishing prerelease with version $VERSION"
npm publish --tag snapshot
else
echo "Publishing full release with version $CURRENT_FULL_VERSION"
echo "Publishing full release with version $VERSION"
npm publish --access public
fi
Loading

0 comments on commit 665d901

Please sign in to comment.