Commit 8e3bc58a authored by Vadim Vlasov's avatar Vadim Vlasov

feat: persist AppGate link across fastlane runs via working-dir cache

Set APPGATE_LINK and APPGATE_LINK_<PLATFORM> on upload and persist them
to a same-pipeline cache file, restoring into ENV on plugin startup so
later fastlane runs or CI jobs on the same checkout (e.g. notify_slack)
can read the link without any Fastfile or CI changes.
parent bf08ed62
......@@ -14,3 +14,13 @@ end
Fastlane::Furylion.all_classes.each do |current|
require current
end
# Restore AppGate download links persisted by an earlier fastlane run that shares
# this working directory (a separate `fastlane` command, or a CI job on the same
# runner/checkout) back into ENV (APPGATE_LINK, APPGATE_LINK_<PLATFORM>), so lanes
# such as notify_slack can read them without any Fastfile/CI changes.
begin
Fastlane::Helper::AppGateHelper.restore_links_into_env
rescue StandardError
nil
end
......@@ -40,9 +40,13 @@ module Fastlane
share_url = release_data[:share_url]
if share_url && !share_url.empty?
ENV["APPGATE_LINK"] = share_url
platform = Actions.lane_context[SharedValues::PLATFORM_NAME]
# Sets ENV (APPGATE_LINK + APPGATE_LINK_<PLATFORM>) for this process AND
# persists to a working-dir cache so a later fastlane run/job can restore it.
Helper::AppGateHelper.persist_link(share_url, platform)
Actions.lane_context[SharedValues::APPGATE_LINK] = share_url
UI.success("AppGate download page: #{share_url}")
exposed = Helper::AppGateHelper.link_env_keys(platform).join(", ")
UI.success("AppGate download page: #{share_url} (exposed as ENV #{exposed})")
else
UI.important("AppGate did not return a share link (older server?); APPGATE_LINK not set.")
end
......
require 'json'
module Fastlane
module Helper
class AppGateHelper
......@@ -19,6 +21,68 @@ module Fastlane
UI.user_error!("Missing required parameter: #{param}") unless params[param]
end
end
# ---- Download-link cache -------------------------------------------------
# ENV set inside one fastlane process does not survive into a separate
# fastlane run / CI job. To let lanes like notify_slack read ENV["APPGATE_LINK"]
# without editing the project, the upload action persists the link to a small
# file in the working directory, and the plugin restores it into ENV on every
# fastlane startup (see restore_links_into_env, called from the plugin entry).
# This bridges separate fastlane invocations that SHARE a working directory
# (e.g. two `fastlane` commands, or CI jobs on the same runner/checkout).
def self.link_cache_path
base = ENV["CI_PROJECT_DIR"]
base = Dir.pwd if base.nil? || base.empty?
File.join(base, ".appgate_links.json")
end
def self.link_env_keys(platform = nil)
keys = ["APPGATE_LINK"]
plat = platform.to_s.strip
keys << "APPGATE_LINK_#{plat.upcase}" unless plat.empty?
keys
end
def self.read_link_cache
path = link_cache_path
return nil unless File.exist?(path)
JSON.parse(File.read(path))
rescue StandardError
nil
end
def self.persist_link(url, platform = nil)
return if url.nil? || url.to_s.empty?
keys = link_env_keys(platform)
keys.each { |k| ENV[k] = url }
pipeline = ENV["CI_PIPELINE_ID"].to_s
data = read_link_cache
data = nil if data && data["pipeline"].to_s != pipeline
data ||= { "pipeline" => pipeline, "links" => {} }
data["pipeline"] = pipeline
data["links"] ||= {}
keys.each { |k| data["links"][k] = url }
File.write(link_cache_path, JSON.generate(data))
rescue StandardError => e
UI.verbose("AppGate: could not persist link cache: #{e.message}") if defined?(UI)
end
def self.restore_links_into_env
data = read_link_cache
return if data.nil?
pipeline = ENV["CI_PIPELINE_ID"].to_s
# Same-pipeline only; allow restore when there is no pipeline context (local runs).
return if !pipeline.empty? && data["pipeline"].to_s != pipeline
(data["links"] || {}).each do |k, v|
ENV[k] = v.to_s if ENV[k].nil? || ENV[k].to_s.empty?
end
rescue StandardError => e
UI.verbose("AppGate: could not restore link cache: #{e.message}") if defined?(UI)
end
# --------------------------------------------------------------------------
def self.create_release(api_key, app_id, branch, file_name, file_size, version = nil, build_number = nil)
url = "#{BASE_URL}/app/#{app_id}/releases"
......
module Fastlane
module Furylion
VERSION = "1.3.2"
VERSION = "1.3.3"
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment