Upgrade to Pro — share decks privately, control downloads, hide ads and more …

🤖 Automating key workflows in your daily develo...

🤖 Automating key workflows in your daily developer life!

In this talk, I want to guide the audience through the tools I implemented and the scripts I built over time in our CI system to automate common tasks like:
- Daily release deliveries to QA (releases run automatically only if there were any new commits since the last one)
- Automated Git(Hub) tags creation for each release
- Automated release notes included in the tags (for QA)
- Automated code formatting with standard rules automatically shared across all the members of a team

I currently work with Bitrise, which means my example may include that tool (but the scripts are tool agnostic).

Avatar for Alessandro Mautone

Alessandro Mautone

May 14, 2022

Other Decks in Programming

Transcript

  1. Overview Automated Git(Hub) tags creation for each release 🤖 Automated

    release notes for each release 📃 Automated code formatting with standard rules automatically shared across all the members of a team 📏
  2. • Daily work fl ow • Check if there are

    any commits since the last available tag • If yes -> generate and push a new tag CI setup
  3. function get_latest_tag_number() { # Gets beta number from format like

    "beta_100" latestTagNumber=${ADDR[1]} } Script - Check commits since last release
  4. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release
  5. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release git pull --rebase git fetch --tags
  6. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)
  7. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag"
  8. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag"
  9. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release get_latest_tag_number
  10. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber
  11. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release generate_new_tag_name export_tag_name
  12. git pull --rebase git fetch --tags get_latest_tag commitsSinceLastTag=$(git log $latestTag..HEAD)

    # Check if there are commits since latest tag if [ -n "$commitsSinceLastTag" ]; then echo "There are commits since last tag" # Splits passed var by speci fi ed separator IFS='_' read -ra ADDR <<<"$latestTag" get_latest_tag_number # Increases beta number latestTagNumber=$(($latestTagNumber + 1)) echo $latestTagNumber generate_new_tag_name export_tag_name else echo "There are NO commits since last tag" exit 1 f Script - Check commits since last release echo "There are NO commits since last tag" exit 1
  13. branch=$(git rev-parse --abbrev-ref HEAD) git tag -a $GIT_BETA_TAG -m "Creating

    new automated tag for qa release" $branch git push --tags Script - Tag creator
  14. Overview Automated Git(Hub) tags creation for each release 🤖 Automated

    release notes for each release 📃 Automated code formatting with standard rules automatically shared across all the members of a team 📏
  15. githubReleasesUrl="https://your-repo/releases" echo "Getting latest release draft id" releaseId=$(curl -u $GITHUB_USERNAME:$GITHUB_TOKEN

    $githubReleasesUrl | jq '.[] | select(.draft == true) | "\(.id)"') releaseIdWithoutQuotes=$(sed -e 's/^"//' -e 's/"$//' <<<"$releaseId") echo "Publishing latest release draft" curl -u $GITHUB_USERNAME:$GITHUB_TOKEN --request PATCH "$githubReleasesUrl/ $releaseIdWithoutQuotes" --header "Content-Type: application/json" --header "Accept: application/json" --data "{\"tag_name\": \"$GIT_BETA_TAG\", \"target_commitish\": \"develop\", \"name\": \"$GIT_BETA_TAG\", \"draft\": false, \"prerelease\": false}" Script - Release publisher
  16. githubReleasesUrl="https://your-repo/releases" echo "Getting latest release draft id" releaseId=$(curl -u $GITHUB_USERNAME:$GITHUB_TOKEN

    $githubReleasesUrl | jq '.[] | select(.draft == true) | "\(.id)"') releaseIdWithoutQuotes=$(sed -e 's/^"//' -e 's/"$//' <<<"$releaseId") echo "Publishing latest release draft" curl -u $GITHUB_USERNAME:$GITHUB_TOKEN --request PATCH "$githubReleasesUrl/ $releaseIdWithoutQuotes" --header "Content-Type: application/json" --header "Accept: application/json" --data "{\"tag_name\": \"$GIT_BETA_TAG\", \"target_commitish\": \"develop\", \"name\": \"$GIT_BETA_TAG\", \"draft\": false, \"prerelease\": false}" Script - Release publisher
  17. githubReleasesUrl="https://your-repo/releases" echo "Getting latest release draft id" releaseId=$(curl -u $GITHUB_USERNAME:$GITHUB_TOKEN

    $githubReleasesUrl | jq '.[] | select(.draft == true) | "\(.id)"') releaseIdWithoutQuotes=$(sed -e 's/^"//' -e 's/"$//' <<<"$releaseId") echo "Publishing latest release draft" curl -u $GITHUB_USERNAME:$GITHUB_TOKEN --request PATCH "$githubReleasesUrl/ $releaseIdWithoutQuotes" --header "Content-Type: application/json" --header "Accept: application/json" --data "{\"tag_name\": \"$GIT_BETA_TAG\", \"target_commitish\": \"develop\", \"name\": \"$GIT_BETA_TAG\", \"draft\": false, \"prerelease\": false}" Script - Release publisher
  18. githubReleasesUrl="https://your-repo/releases" echo "Getting latest release draft id" releaseId=$(curl -u $GITHUB_USERNAME:$GITHUB_TOKEN

    $githubReleasesUrl | jq '.[] | select(.draft == true) | "\(.id)"') releaseIdWithoutQuotes=$(sed -e 's/^"//' -e 's/"$//' <<<"$releaseId") echo "Publishing latest release draft" curl -u $GITHUB_USERNAME:$GITHUB_TOKEN --request PATCH "$githubReleasesUrl/ $releaseIdWithoutQuotes" --header "Content-Type: application/json" --header "Accept: application/json" --data "{\"tag_name\": \"$GIT_BETA_TAG\", \"target_commitish\": \"develop\", \"name\": \"$GIT_BETA_TAG\", \"draft\": false, \"prerelease\": false}" Script - Release publisher
  19. githubReleasesUrl="https://your-repo/releases" echo "Getting latest release draft id" releaseId=$(curl -u $GITHUB_USERNAME:$GITHUB_TOKEN

    $githubReleasesUrl | jq '.[] | select(.draft == true) | "\(.id)"') releaseIdWithoutQuotes=$(sed -e 's/^"//' -e 's/"$//' <<<"$releaseId") echo "Publishing latest release draft" curl -u $GITHUB_USERNAME:$GITHUB_TOKEN --request PATCH "$githubReleasesUrl/ $releaseIdWithoutQuotes" --header "Content-Type: application/json" --header "Accept: application/json" --data "{\"tag_name\": \"$GIT_BETA_TAG\", \"target_commitish\": \"develop\", \"name\": \"$GIT_BETA_TAG\", \"draft\": false, \"prerelease\": false}" Script - Release publisher
  20. Overview Automated Git(Hub) tags creation for each release 🤖 Automated

    release notes for each release 📃 Automated code formatting with standard rules automatically shared across all the members of a team 📏
  21. spotless { // optional: limit format enforcement to just the

    fi les changed by this feature branch ratchetFrom 'origin/main' kotlin { ktlint() // or ktfmt() or others trimTrailingWhitespace() indentWithTabs() // or spaces. Takes an integer argument if you don't like 4 endWithNewline() licenseHeader '/* (C)$YEAR */' // or licenseHeaderFile } kotlinGradle { target '*.gradle.kts' // default target for kotlinGradle ktlint() // or ktfmt() or prettier() } } Spotless - configuration
  22. task createSpotlessPreCommitHook() { def gitHooksDirectory = new File("$project.rootDir/.git/hooks/") if (!gitHooksDirectory.exists())

    gitHooksDirectory.mkdirs() new File("$project.rootDir/.git/hooks", "pre-commit").text = """ #!/bin/bash echo "Running spotless check" ./gradlew spotlessApply if [ \$? -eq 0 ] then echo "Spotless check succeed" git add . else echo "Spotless check failed" >&2 exit 1 fi """ "chmod +x .git/hooks/pre-commit".execute() } Spotless - configuration
  23. data class Bike(val name: String, val model: String, val brand:

    String) Spotless - Result data class Bike( val name: String, val model: String, val brand: String ) Before After
  24. if(contentSize = storageAvailable) { displayFullStorageMessage() } Spotless - Result if(contentSize

    = storageAvailable) { displayFullStorageMessage() } Before After
  25. Overview Automated Git(Hub) tags creation for each release 🤖 Automated

    release notes for each release 📃 Automated code formatting with standard rules automatically shared across all the members of a team 📏