From 8a8574449e62f07ee6baf74fe5b2a0bfeb6adb16 Mon Sep 17 00:00:00 2001 From: Mathew Gacy Date: Wed, 3 Jan 2024 10:17:40 -0700 Subject: [PATCH] Workflow Updates (#134) * Update action versions * Formatting * Cache dependencies * Rename * Add release instructions * Require passing tests before release * Create release from tag * Tweak instructions --- .../{tag-release.yml => create-release.yml} | 28 ++++++++++++++++--- .../{release.yml => prepare-release.yml} | 11 +++----- .github/workflows/tests.yml | 14 +++++++++- RELEASE.md | 3 ++ 4 files changed, 44 insertions(+), 12 deletions(-) rename .github/workflows/{tag-release.yml => create-release.yml} (58%) rename .github/workflows/{release.yml => prepare-release.yml} (88%) create mode 100644 RELEASE.md diff --git a/.github/workflows/tag-release.yml b/.github/workflows/create-release.yml similarity index 58% rename from .github/workflows/tag-release.yml rename to .github/workflows/create-release.yml index 3a6e0b4..75031e1 100644 --- a/.github/workflows/tag-release.yml +++ b/.github/workflows/create-release.yml @@ -1,4 +1,4 @@ -name: Tag Release +name: Create Release on: pull_request: types: @@ -7,12 +7,19 @@ on: - 'main' jobs: - tag: + test: + name: Test + if: github.event.pull_request.merged == true && github.head_ref == 'release' + uses: lytics/ios-sdk/.github/workflows/tests.yml@main + + release: + name: Release + needs: test runs-on: ubuntu-latest if: github.event.pull_request.merged == true && github.head_ref == 'release' steps: - name: Git checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get version id: get-version @@ -29,7 +36,7 @@ jobs: private_key: ${{ secrets.FRONTEND_PROJECT_BOT_TOKEN }} - name: Push tag - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{ steps.generate-token.outputs.token }} script: | @@ -39,3 +46,16 @@ jobs: ref: 'refs/tags/${{ env.current-version }}', sha: '${{ github.sha }}' }) + + - name: Create release + uses: actions/github-script@v7 + with: + github-token: ${{ steps.generate-token.outputs.token }} + script: | + github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: '${{ env.current-version }}', + draft: false, + prerelease: false + }) diff --git a/.github/workflows/release.yml b/.github/workflows/prepare-release.yml similarity index 88% rename from .github/workflows/release.yml rename to .github/workflows/prepare-release.yml index 372bcbb..e51ca3c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/prepare-release.yml @@ -1,4 +1,4 @@ -name: Release +name: Prepare Release on: workflow_dispatch: inputs: @@ -10,13 +10,13 @@ on: - patch - minor - major - + jobs: release: runs-on: ubuntu-latest steps: - name: Git checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Bump Version file id: bump @@ -33,7 +33,7 @@ jobs: with: app_id: ${{ vars.FRONTEND_PROJECT_BOT_APP_ID }} private_key: ${{ secrets.FRONTEND_PROJECT_BOT_TOKEN }} - + - name: Create pull request id: cpr uses: peter-evans/create-pull-request@v4 @@ -46,8 +46,5 @@ jobs: title: '[CI] Bump Version (${{ steps.bump.outputs.version }})' body: | Update `Version.swift` with bumped version number - - Auto-generated by [create-pull-request][1] - - [1]: https://github.com/peter-evans/create-pull-request draft: false token: ${{ steps.generate-token.outputs.token }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7510e6b..65f5cc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,7 @@ name: Tests on: + workflow_call: workflow_dispatch: push: branches: [ main ] @@ -17,16 +18,27 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: .build + key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} + restore-keys: | + ${{ runner.os }}-spm- + - name: Build and test uses: mxcl/xcodebuild@v1 with: xcode: ^14 platform: iOS code-coverage: true + - name: Convert coverage uses: sersoft-gmbh/swift-coverage-action@v3 id: coverage-files + - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..ab83f7c --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +# Release Instructions + +This package uses the [swift-version-file-plugin](https://github.com/Mobelux/swift-version-file-plugin) Swift Package Manager command plugin to maintain a source file--[`Sources/Lytics/Version.swift`](Sources/Lytics/Version.swift)--enabling the SDK to report its version to the Lytics API. To ensure that this is properly maintained, releases should only be created using the [`Prepare Release`](https://github.com/lytics/ios-sdk/actions/workflows/prepare-release.yml) workflow. Run it using `workflow_dispatch` event trigger from the `main` branch with the appropriate release type to create a new PR on a `release` branch containing an update to the Version file. Add any additional changes related to the release, like updating a changelog, to this PR. Finally, merge the `release` branch into `main` to delete it and trigger the [`Create Release`](.github/workflows/create-release.yml) workflow. This will create a new tag corresponding to the value of the updated Version file and a new release.