Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Flank release job from Bitrise to GitHub Actions #892

Closed
bootstraponline opened this issue Jul 16, 2020 · 1 comment · Fixed by #910
Closed

Move Flank release job from Bitrise to GitHub Actions #892

bootstraponline opened this issue Jul 16, 2020 · 1 comment · Fixed by #910
Assignees
Labels

Comments

@bootstraponline
Copy link
Contributor

bootstraponline commented Jul 16, 2020

Author the user story for this feature

As a developer on Flank, I want to move the release job to GitHub actions so I can automatically release new versions of Flank.


The Flank release job on Bitrise sometimes flakes out. Let's move all the bitrise jobs to GitHub actions. As part of migrating the release job, we should probably build a Kotlin CLI that automates the release. Then the GitHub Action will simply invoke this Kotlin CLI that has the complex release logic.

Example error:

+ jfrog bt mcs flank/maven/flank/v20.07.0
[Info] Requesting content sync...
[Error] bintray response: 404 Not Found
{
  "message": "Version 'v20.07.0' was not found"
}

Any part of the release process can fail. Maven sync is particularly flaky. The Kotlin wrapper code should be smart enough to intelligently retry on error after a delay.

Here's the bitrise job yaml:

---
format_version: '4'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
workflows:
  primary:
    steps:
    - script:
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -euxo pipefail

            curl -L https://github.com/github/hub/releases/download/v2.12.8/hub-linux-amd64-2.12.8.tgz | tar xvz
            mv hub-*/bin/hub .

            envman add --key PATH --value "`pwd`:$PATH"
        title: Install hub
    - script:
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -euxo pipefail

            hub --version
        title: Check hub version
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
        title: Activate SSH key
    - git-clone: {}
    - cache-pull: {}
    - script:
        title: Set flank version.txt
        inputs:
        - content: |
            #!/usr/bin/env bash
            set -ex

            # when triggered from a tag push BITRISE_GIT_TAG will already be defined
            # if BITRISE_GIT_TAG is null (-z) then we'll use flank_snapshot
            if [[ -z "$BITRISE_GIT_TAG" ]]; then
              BITRISE_GIT_TAG=flank_snapshot
              envman add --key MVN_VERSION --value "$BITRISE_GIT_TAG"
            else
              # drop leading v for maven. v4.4 -> 4.4
              envman add --key MVN_VERSION --value "${BITRISE_GIT_TAG:1}"
            fi

            echo "$BITRISE_GIT_TAG" > ./test_runner/src/main/resources/version.txt
            envman add --key SNAPSHOT_TAG --value $BITRISE_GIT_TAG

            echo "$GIT_CLONE_COMMIT_HASH" > ./test_runner/src/main/resources/revision.txt
            envman add --key MVN_REVISION --value $GIT_CLONE_COMMIT_HASH

            # Update bugsnag
            curl https://build.bugsnag.com/ \
                --header "Content-Type: application/json" \
                --data '{
                  "apiKey": "$BUGSNAG_KEY",
                  "appVersion": "'"$GIT_CLONE_COMMIT_HASH"'",
                  "releaseStage": "production",
                  "builderName": "bitrise",
                  "sourceControl": {
                    "provider": "github",
                    "repository": "https://github.com/Flank/flank",
                    "revision": "'"$GIT_CLONE_COMMIT_HASH"'"
                  },
                  "metadata": {"bitrise_build": "'"$BITRISE_BUILD_URL"'"}
                }'
    - script:
        title: Delete old snapshot
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -x

            curl -fL https://getcli.jfrog.io | sh
            ./jfrog bt config --user $MVN_USER --key $MVN_KEY --licenses Apache-2.0
            ./jfrog bt version-delete flank/maven/flank/$MVN_VERSION --quiet

            exit 0
    - gradle-runner:
        inputs:
        - gradle_task: "-p test_runner clean build shadowJar"
        - gradlew_path: "./test_runner/gradlew"
        - cache_level: all
        title: test_runner clean build shadowJar
    - gradle-runner:
        inputs:
        - gradlew_path: "./test_runner/gradlew"
        - gradle_task: "-p test_runner bintrayUpload"
        title: Gradle bintrayUpload
    - script:
        title: Rename flank jar
        inputs:
        - content: |
            #!/usr/bin/env bash

            set -euxo pipefail

            ls -la ./test_runner/build/libs/
            mv ./test_runner/build/libs/flank.jar "$BITRISE_DEPLOY_DIR/flank.jar"

            envman add --key COMMIT_HASH --value ${GIT_CLONE_COMMIT_HASH:0:7}
    - script:
        title: Hub remove old release
        inputs:
        - content: |-
            #!/usr/bin/env bash

            set -e

            # Authorize hub
            mkdir -p ~/.config/

            cat << EOF > ~/.config/hub
            github.com:
            - user: bootstraponline
              oauth_token: $GH_TOKEN
              protocol: https
            EOF

            # Verify hub is on path
            hub --version

            # Disable error reporting because we're expecting an error.
            set +e

            hub release delete "$SNAPSHOT_TAG"

            exit 0
    - script:
        inputs:
        - content: |-
            #!/usr/bin/env bash

            # Only delete if tag is latest. Otherwise we'll go into a tag delete/trigger loop!
            if [[ "$SNAPSHOT_TAG" = "flank_snapshot" ]]; then
              curl -u bootstraponline:$GH_TOKEN -X "DELETE" "https://api.github.com/repos/Flank/flank/git/refs/tags/$SNAPSHOT_TAG"
            fi

            exit 0
        title: Remove old tag
    - script:
        run_if: enveq "SNAPSHOT_TAG" "flank_snapshot"
        title: Release - Snapshot Only
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -ex

            hub release create -p -a "$BITRISE_DEPLOY_DIR/flank.jar" -m "Flank $BITRISE_GIT_TAG" -m "Snapshot release for commit $COMMIT_HASH" "$SNAPSHOT_TAG"
    - script:
        run_if: not (enveq "SNAPSHOT_TAG" "flank_snapshot")
        title: Release - Stable Only
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -ex

            hub release create -a "$BITRISE_DEPLOY_DIR/flank.jar" -m "Flank $BITRISE_GIT_TAG" -m "Stable release for commit $COMMIT_HASH" "$SNAPSHOT_TAG"
    - script@1:
        title: Maven Central Sync
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -ex

            # Sync bintray to maven central
            jfrog bt mcs flank/maven/flank/"$SNAPSHOT_TAG"
    - cache-push:
        is_always_run: true
        inputs:
        - cache_paths: |
            $BITRISE_CACHE_DIR
            /root/.gradle
app:
  envs:
  - DONT_PUT_SECRETS_HERE: THIS_IS_A_PUBLIC_JOB
  - opts:
      is_expand: false
    SNAPSHOT_TAG: flank_snapshot
trigger_map:
- push_branch: master
  workflow: primary
- tag: v*
  workflow: primary
@piotradamczyk5
Copy link
Contributor

piotradamczyk5 commented Jul 22, 2020

Steps to do in this PR

  1. Create Empty template for each step on github action
  2. Install GitHub hub not needed cause it is build in macOS machine
  3. Check hub version not needed, see step 2, version 2.14.2
  4. Get and set tag as environment variable
  5. Update bugsnag
  6. Delete old snapshot
  7. [Gradle] Build flank (just invoke it using github actions)
  8. [Gradle] Upload to bintray(just invoke it using github actions)
  9. Rename flank jar
  10. Hub remove old release
  11. Remove old tag
    12a. if snapshot version release snapshot
    12b. if not snapshot version release stable
  12. Sync bintray to maven central
  13. Create documentation

piotradamczyk5 added a commit that referenced this issue Jul 22, 2020
piotradamczyk5 added a commit that referenced this issue Jul 30, 2020
piotradamczyk5 added a commit that referenced this issue Jul 30, 2020
Create release workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants