github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/.github/workflows/mobile-release.yml (about)

     1  name: Mobile-release
     2  
     3  on:
     4    release:
     5      types: [released]
     6  
     7  jobs:
     8    build:
     9      runs-on: ubuntu-latest
    10  
    11      steps:
    12        - uses: actions/checkout@v4
    13  
    14        - name: Set env
    15          run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
    16  
    17        - name: Get Release
    18          run: |
    19            echo $RELEASE_VERSION
    20            echo ${{ env.RELEASE_VERSION }}
    21  
    22        - name: Checkout tools repo
    23          uses: actions/checkout@v4
    24          with:
    25            repository: mysteriumnetwork/mysterium-mobile-provider
    26            ref: 'master'
    27            path: mobile-app
    28            token: ${{ secrets.REPO_TOKEN }}
    29  
    30        - name: Update version
    31          run: |
    32            APP_VERSION=$(echo "$(grep "versionName" "./mobile-app/android/app/build.gradle.kts" | awk -F '"' '{print $2}')" + 0.1 | bc)
    33            sed -i -E "/versionName\s*=\s*\"[0-9]+\.[0-9]+\"/s/\"[0-9]+\.[0-9]+\"/\"$APP_VERSION\"/" "./mobile-app/android/app/build.gradle.kts"
    34            sed -i -E "/node\s*=\s*\"[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?\"/s/\"[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?\"/\"${{ env.RELEASE_VERSION }}\"/" "./mobile-app/android/gradle/libs.versions.toml"
    35  
    36        - name: Pushes to another repository
    37          id: push_directory
    38          uses: cpina/github-action-push-to-another-repository@main
    39          env:
    40            API_TOKEN_GITHUB: ${{ secrets.REPO_TOKEN }}
    41          with:
    42            source-directory: mobile-app
    43            destination-github-username: 'mysteriumnetwork'
    44            destination-repository-name: 'mysterium-mobile-provider'
    45            user-email: core-services@mysterium.network
    46            commit-message: Create release version ${{ env.RELEASE_VERSION }}
    47            target-branch: master
    48  
    49        - name: Send pull-request
    50          env:
    51            GH_TOKEN: ${{ secrets.REPO_TOKEN }}
    52          run: |
    53            LATEST_TAG=$(git describe --tags --always --abbrev=0)
    54            REPOSITORY="mysteriumTeam/mysterium-mobile-provider"
    55            FOLDER="bin/$REPOSITORY"
    56            BRANCH_NAME="release-$LATEST_TAG"
    57  
    58            # Clone the remote repository and change working directory to the
    59            # folder it was cloned to.
    60            git clone \
    61              --depth=1 \
    62              --branch=bitrise \
    63              https://mpolubotko:${{ secrets.REPO_TOKEN }}@github.com/$REPOSITORY \
    64              $FOLDER
    65  
    66            cd $FOLDER
    67  
    68            # Setup the committers identity.
    69            git config user.email "core-services@mysterium.network"
    70            git config user.name "MysteriumTeam"
    71  
    72            # Create a new feature branch for the changes.
    73            git checkout -b $BRANCH_NAME
    74  
    75            # Update the script files to the latest version.
    76            cp -R ../../../mobile-app/android android
    77  
    78            # Commit the changes and push the feature branch to origin
    79            git add .
    80            git commit -m "update files for new release version $LATEST_TAG"
    81            git push origin $BRANCH_NAME
    82  
    83            # Store the PAT in a file that can be accessed by the
    84            # GitHub CLI.
    85            echo "${{ secrets.REPO_TOKEN }}" > token.txt
    86  
    87            # Authorize GitHub CLI for the current repository and
    88            # create a pull-request containing the updates.
    89            PR_URL=$(gh pr create \
    90              --body "" \
    91              --title "Release $LATEST_TAG" \
    92              --head "$BRANCH_NAME" \
    93              --base "master" \
    94              | sed -n 's#https://github\.com/[^/]\+/[^/]\+/\pull/\([0-9]\+\).*#\1#p')
    95            echo "PR_NUMBER=$PR_URL" >> $GITHUB_ENV
    96  
    97        - name: Approve Pull Request
    98          env:
    99            GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
   100            REPO_OWNER: "MysteriumTeam"
   101            REPO_NAME: "mysterium-mobile-provider"
   102            PR_NUMBER: ${{ env.PR_NUMBER }}
   103          run: | 
   104            response=$(curl -s -o /dev/null -w "%{http_code}" -L -X PUT \
   105              -H "Accept: application/vnd.github+json" \
   106              -H "Authorization: Bearer $GITHUB_TOKEN" \
   107              -H "X-GitHub-Api-Version: 2022-11-28" \
   108              https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER/merge \
   109              -d '{"commit_title":"Release v${{ env.RELEASE_VERSION }}","commit_message":"${{ env.RELEASE_VERSION }}"}')
   110            
   111            # Check HTTP response
   112            if [ "$response" == "204" ] || [ "$response" == "200" ] || [ "$response" == "201" ]; then
   113              echo "PR was approved successfully"
   114            else
   115              echo "Couldn't approved PR, HTTP-status: $response"
   116              exit 1  
   117            fi
   118        
   119        - name: "Call Bitrise API"
   120          uses: indiesdev/curl@v1.1
   121          with:
   122            url: https://api.bitrise.io/v0.1/apps/${{ secrets.BITRISE_APP_ID }}/builds
   123            method: "POST"
   124            id: api
   125            accept: 200, 201
   126            headers: '{ "accept": "application/json", "Authorization": "${{ secrets.BITRISE_TOKEN }}", "Content-Type": "application/json" }'
   127            body: '{ "hook_info": {"type": "bitrise"}, "build_params": {"branch":"master", "workflow_id":"build"}}'
   128            timeout: 10000
   129            log-response: true
   130  
   131        - name: "Bitrise response"
   132          run: echo ${{ steps.api.outputs.response }}