diff --git a/.gitea/workflows/beta.yml b/.gitea/workflows/beta.yml index 5f52542..417e6f6 100644 --- a/.gitea/workflows/beta.yml +++ b/.gitea/workflows/beta.yml @@ -9,9 +9,6 @@ jobs: build-and-upload: runs-on: macos-build - env: - BUILD_NUMBER: ${{ github.run_number }} - steps: - name: Checkout repository (workaround - Gitea git-upload-pack bug, see go-gitea/gitea#21819) run: | @@ -55,3 +52,78 @@ jobs: - name: Clean up API key if: always() run: rm -f fastlane/apikey.json + + - name: Email notification + if: always() + env: + SMTP_USER: ${{ secrets.SMTP_USER }} + SMTP_PASS: ${{ secrets.SMTP_PASS }} + NOTIFY_EMAIL_TO: ${{ secrets.NOTIFY_EMAIL_TO }} + run: | + STATUS="${{ job.status }}" + WORKFLOW="${{ github.workflow }}" + JOB="${{ github.job }}" + BRANCH="${{ github.ref_name }}" + COMMIT="${{ github.sha }}" + COMMIT_SHORT="${COMMIT:0:7}" + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + YEAR="$(date +%Y)" + + if [ "$STATUS" = "success" ]; then + BADGE_BG="#dcfce7"; BADGE_FG="#166534"; BADGE_LABEL="SUCESSO"; TITLE="Pipeline concluído com sucesso" + else + BADGE_BG="#fee2e2"; BADGE_FG="#991b1b"; BADGE_LABEL="FALHA"; TITLE="Pipeline falhou" + fi + + SUBJECT="[PediFoods CI] ${BADGE_LABEL} - ${WORKFLOW}" + + HTML_BODY=$(cat < + + + + + ${SUBJECT} + + + + +
+ + + + +
+ Atomenta +
+
${BADGE_LABEL}
+

${TITLE}

+ + + + + +
Workflow:${WORKFLOW}
Job:${JOB}
Branch:${BRANCH}
Commit:${COMMIT_SHORT}
+ +
© ${YEAR} Atomenta
+
+ + + HTMLEOF + ) + + { + printf 'From: Atomenta CI <%s>\r\n' "$SMTP_USER" + printf 'To: %s\r\n' "$NOTIFY_EMAIL_TO" + printf 'Subject: %s\r\n' "$SUBJECT" + printf 'MIME-Version: 1.0\r\n' + printf 'Content-Type: text/html; charset=UTF-8\r\n' + printf '\r\n' + printf '%s\r\n' "$HTML_BODY" + } | curl --silent --show-error \ + --url "smtp://mail.loverde.com.br:587" \ + --ssl-reqd \ + --mail-from "$SMTP_USER" \ + --mail-rcpt "$NOTIFY_EMAIL_TO" \ + --user "$SMTP_USER:$SMTP_PASS" \ + --upload-file - || true diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index f0e04d0..970cdee 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -24,3 +24,78 @@ jobs: - name: Run tests with coverage run: fastlane tests + + - name: Email notification + if: always() + env: + SMTP_USER: ${{ secrets.SMTP_USER }} + SMTP_PASS: ${{ secrets.SMTP_PASS }} + NOTIFY_EMAIL_TO: ${{ secrets.NOTIFY_EMAIL_TO }} + run: | + STATUS="${{ job.status }}" + WORKFLOW="${{ github.workflow }}" + JOB="${{ github.job }}" + BRANCH="${{ github.ref_name }}" + COMMIT="${{ github.sha }}" + COMMIT_SHORT="${COMMIT:0:7}" + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + YEAR="$(date +%Y)" + + if [ "$STATUS" = "success" ]; then + BADGE_BG="#dcfce7"; BADGE_FG="#166534"; BADGE_LABEL="SUCESSO"; TITLE="Pipeline concluído com sucesso" + else + BADGE_BG="#fee2e2"; BADGE_FG="#991b1b"; BADGE_LABEL="FALHA"; TITLE="Pipeline falhou" + fi + + SUBJECT="[PediFoods CI] ${BADGE_LABEL} - ${WORKFLOW}" + + HTML_BODY=$(cat < + + + + + ${SUBJECT} + + + + +
+ + + + +
+ Atomenta +
+
${BADGE_LABEL}
+

${TITLE}

+ + + + + +
Workflow:${WORKFLOW}
Job:${JOB}
Branch:${BRANCH}
Commit:${COMMIT_SHORT}
+ +
© ${YEAR} Atomenta
+
+ + + HTMLEOF + ) + + { + printf 'From: Atomenta CI <%s>\r\n' "$SMTP_USER" + printf 'To: %s\r\n' "$NOTIFY_EMAIL_TO" + printf 'Subject: %s\r\n' "$SUBJECT" + printf 'MIME-Version: 1.0\r\n' + printf 'Content-Type: text/html; charset=UTF-8\r\n' + printf '\r\n' + printf '%s\r\n' "$HTML_BODY" + } | curl --silent --show-error \ + --url "smtp://mail.loverde.com.br:587" \ + --ssl-reqd \ + --mail-from "$SMTP_USER" \ + --mail-rcpt "$NOTIFY_EMAIL_TO" \ + --user "$SMTP_USER:$SMTP_PASS" \ + --upload-file - || true diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 183bbfe..aa363d4 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -1,8 +1,32 @@ # This file contains the fastlane.tools configuration for the PediFoods iOS app. # You can find the documentation at https://docs.fastlane.tools +require "date" +require "json" +require "fileutils" + default_platform(:ios) +# Build number scheme: "YYYY.MM.DD.0.0." - increments across +# builds made on the same calendar day, resets to 1 on a new day. +# Needs somewhere to remember "the last used, and for which day", +# and the per-run checkout under .cache/act// can't be +# that place - each CI run gets a fresh, throwaway clone, so anything +# written there is gone by the next run. State lives instead at a fixed +# path under this CI user's home directory on the Mac mini runner, +# which is the same machine/user across every run. +def next_build_version + state_path = File.expand_path("~/ci-build-version-state/pedifoods.json") + FileUtils.mkdir_p(File.dirname(state_path)) + + today = Date.today.strftime("%Y.%m.%d") + state = File.exist?(state_path) ? JSON.parse(File.read(state_path)) : {} + build_number = (state["date"] == today) ? state["build_number"].to_i + 1 : 1 + + File.write(state_path, JSON.generate({ "date" => today, "build_number" => build_number })) + "#{today}.0.0.#{build_number}" +end + lane :tests do run_tests( scheme: "PediFoods", @@ -16,10 +40,19 @@ lane :assemble do |options| # Manual signing (team/identity/profile) for the "PediFoods" target is # baked directly into PediFoods.xcodeproj's own project settings - not # overridden here. - # agvtool needs VERSIONING_SYSTEM = apple-generic, which this project doesn't - # set, so it silently no-ops - pass CURRENT_PROJECT_VERSION directly instead. - xcargs = "-skipPackagePluginValidation -skipMacroValidation" - xcargs += " CURRENT_PROJECT_VERSION=#{ENV['BUILD_NUMBER']}" if ENV["BUILD_NUMBER"] + # + # CURRENT_PROJECT_VERSION IS overridden here, with next_build_version + # (see top of file) rather than the project's own committed value. + # Earlier versions of this lane either used the committed value as-is + # (fine until you forget to bump it and Apple rejects a duplicate + # build number) or overrode it with the CI job's raw run-number + # counter (BUILD_NUMBER = github.run_number-style, which silently + # uploaded a build as "51" with no relation to the real version at + # all). next_build_version keeps the real date-based scheme and + # bumps only the last component automatically, so every push + # is guaranteed a fresh, correctly-formatted, ever-increasing build + # number with no manual edit needed before each run. + xcargs = "-skipPackagePluginValidation -skipMacroValidation CURRENT_PROJECT_VERSION=#{next_build_version}" build_app( scheme: "PediFoods",