Merge pull request #73 from superwall-me/develop #2
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Build, Test & Publish | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: write | |
# Prevents running a bunch of we push right back to back | |
concurrency: | |
group: test-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: android-large-runner | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set Up JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' # See 'Supported distributions' for available options | |
java-version: '17' | |
cache: 'gradle' | |
# Allow us to run the command | |
- name: Change wrapper permissions | |
run: chmod +x ./gradlew | |
# Run Build & Test the Project | |
- name: Build gradle project | |
run: ./gradlew build | |
# See what version we're on | |
# Writes to superwall/build/version.json with the version set | |
# in the superwall build.gradle | |
- name: Generate version from config | |
run: ./gradlew :superwall:generateBuildInfo | |
- name: Get Version | |
uses: notiz-dev/github-action-json-property@release | |
id: version | |
with: | |
path: "superwall/build/version.json" | |
prop_path: "version" | |
# Only try to publish if we're on main | |
- name: Check if tag exists | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
id: check-tag | |
run: | | |
EXISTS=$(git tag -l | grep -Fxq "${{steps.version.outputs.prop}}" && echo 'true' || echo 'false') | |
echo "::set-output name=tag-exists::$EXISTS" | |
- name: Tag | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
run: | | |
if [ "${{ steps.check-tag.outputs.tag-exists }}" == "false" ]; then | |
sudo git config --global user.name 'Jake' | |
sudo git config --global user.email '[email protected]' | |
sudo git pull | |
echo "\n\n\n- - - - - VERSION - - - - -\n\n\n" | |
echo ${{steps.version.outputs.prop}} | |
echo "\n\n\n- - - - - END VERSION - - - - -\n\n\n" | |
sudo git tag -a ${{steps.version.outputs.prop}} -m "tags with latest version" | |
sudo git push --tags | |
sudo git checkout -b release/${{steps.version.outputs.prop}} | |
sudo git push -u origin release/${{steps.version.outputs.prop}} | |
fi | |
- name: Deploy | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
run: | | |
if [ "${{ steps.check-tag.outputs.tag-exists }}" == "false" ]; then | |
./gradlew publish -Paws_access_key_id=$AWS_ACCESS_KEY_ID -Paws_secret_access_key=$AWS_SECRET_ACCESS_KEY | |
fi | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Determine prerelease status | |
id: prerelease | |
run: | | |
VERSION=${{steps.version.outputs.prop}} | |
if [[ "$VERSION" == *"-alpha"* || "$VERSION" == *"-beta"* || "$VERSION" == *"-rc"* ]]; then | |
echo "::set-output name=status::true" | |
else | |
echo "::set-output name=status::false" | |
fi | |
- name: slack-send | |
# Only notify on a new tag | |
if: steps.check-tag.outputs.tag-exists == 'false' | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{ | |
"text": "Please create a new Android Release! https://github.com/superwall-me/Superwall-Android/releases/new?tag=${{steps.version.outputs.prop}}&prerelease=${{steps.prerelease.outputs.status}}" | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |