discharger 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3212b79aa38f448d44523f2f83b622c7dfec1cff7bff08ed6033bbe1fea79761
4
- data.tar.gz: 6d9d0c008a85560a666522c58a97ee08feae68ef1ea4e8f7cda86e29b0e8bd75
3
+ metadata.gz: '0438319d582d725e71df1e9fdaf270f8036bc78f1f3c8c01b0bd4038d251e981'
4
+ data.tar.gz: 862ac9091b25ac1a179768f251db61a8aa2b9bcd9b6b1be6848aeb41e8687d66
5
5
  SHA512:
6
- metadata.gz: a54728bf513a01a7f4f91507d0951f4075ab8d2fbd7a80cb01223bbd967f4f5bcc0dfba8a8842a3d3e6ab30c94995180bef978089c19a519ac07de608234f787
7
- data.tar.gz: bf5d95387d7f861cfef6041871c39a946f986225a8c20aa3597b5dc3d5840e5f3ac16ebe5babc354da4b292e84820bcf8cc5a75b56d519414c12614e325a350b
6
+ metadata.gz: c237780b6041dd817e2d3c8e48ee0eebd98e8af7103c91c52d4725c0436c37c3312b7acdb60c70fcd86b660a18086cebd4ff24746921d6eb75a010f896e307b3
7
+ data.tar.gz: 89dd92c5c832f9cee93ae0866711ad0b8989c0c6eade619e14eccff38db6e9740bdad00a97779809b5695c4f5d55763e504422858f8f0f5c7bc1d0279712448d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## [0.4.2] - 2026-09-30
9
+
10
+ ### Added
11
+
12
+ - database.db_name in setup.yml sets the exported DB_NAME, or false leaves it to database.yml (836e811)
13
+
14
+ ### Fixed
15
+
16
+ - The generated bin/setup stores a gh token only after the GitHub Packages source accepts it (1ef5a44)
17
+
8
18
  ## [0.4.1] - 2026-09-29
9
19
 
10
20
  ### Added
@@ -25,19 +35,3 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
25
35
  - Releases finish when the Slack token is missing or the post fails (3cf9b6d)
26
36
  - bin/setup bootstraps a fresh clone: GitHub Packages credentials, bundle install, then re-exec under bundle exec (7196fe4)
27
37
  - github_packages stores bundler credentials only after the source accepts them (41fab0f)
28
-
29
- ## [0.4.0] - 2026-09-24
30
-
31
- ### Added
32
-
33
- - pr_label option opening the finalize and version-bump PRs via gh with that label (08e1d10)
34
-
35
- ### Changed
36
-
37
- - Auto-deploy releases tag the newest commit that changed the version's changelog section instead of requiring it at HEAD, and no longer open a production PR (476fe1b)
38
- - Auto-deploy releases merge the release tag into the production branch (a7a1b49)
39
-
40
- ### Fixed
41
-
42
- - retain_changelogs reaches Reissue, so finalize writes the archived changelog file (2a90edf)
43
- - release:prepare branches from origin, so a stale local branch no longer yields an empty changelog (8eb5fd3)
data/README.md CHANGED
@@ -209,12 +209,12 @@ After installing Discharger, run the setup script to configure your development
209
209
  $ bin/setup
210
210
  ```
211
211
 
212
- This script is idempotent - you can run it multiple times safely, and it will ensure your environment is properly configured.
212
+ You can rerun it whenever your environment drifts. Every run drops and rebuilds the development and test databases, so local data is lost.
213
213
 
214
214
  It works on a fresh clone with no gems installed. The generated script first runs a
215
215
  standard-library-only pass that stores bundler credentials for a configured
216
- `github_packages` source (from your GitHub CLI login, when its token has the
217
- `read:packages` scope), installs the bundle, and then
216
+ `github_packages` source (from your GitHub CLI login, only once the source
217
+ accepts that token), installs the bundle, and then
218
218
  re-execs itself under `bundle exec` so default gems such as psych never clash with
219
219
  `Gemfile.lock`. The `DISCHARGER_SETUP_BUNDLED` environment variable marks the second
220
220
  pass; the `github_packages` step later verifies the stored credentials and warns when
@@ -250,6 +250,9 @@ database:
250
250
  name: "db-your-app"
251
251
  version: "14"
252
252
  password: "postgres"
253
+ # Optional. DB_NAME exported before Rails boots; defaults to the container
254
+ # name without "db-". false leaves it to database.yml.
255
+ # db_name: "your-app"
253
256
  # Optional. Controls how the docker step handles a native PostgreSQL
254
257
  # already listening on the configured port:
255
258
  # omitted/nil/false - silently skip Docker and use the native instance (legacy default)
@@ -318,7 +321,7 @@ The `steps` array specifies which built-in setup commands to run. Available comm
318
321
  - `docker` - Setup Docker containers
319
322
  - `pg_tools` - Create Docker-aware `pg_dump` and `psql` wrappers for apps that use `structure.sql` or call those tools directly
320
323
  - `env` - Configure environment variables
321
- - `database` - Setup and migrate database
324
+ - `database` - Drop and recreate the development and test databases, load the schema, migrate, and seed. Every run resets local data.
322
325
 
323
326
  ### Selecting Specific Steps
324
327
 
@@ -39,7 +39,7 @@ module Discharger
39
39
  end
40
40
 
41
41
  class DatabaseConfig
42
- attr_accessor :port, :name, :version, :password, :prefer_docker
42
+ attr_accessor :port, :name, :version, :password, :prefer_docker, :db_name
43
43
 
44
44
  def initialize
45
45
  @port = 5432
@@ -47,6 +47,7 @@ module Discharger
47
47
  @version = "14"
48
48
  @password = "postgres"
49
49
  @prefer_docker = nil
50
+ @db_name = nil
50
51
  end
51
52
 
52
53
  def from_hash(hash)
@@ -55,6 +56,7 @@ module Discharger
55
56
  @version = hash["version"] if hash["version"]
56
57
  @password = hash["password"] if hash["password"]
57
58
  @prefer_docker = hash["prefer_docker"] if hash.key?("prefer_docker")
59
+ @db_name = hash["db_name"] if hash.key?("db_name")
58
60
  end
59
61
  end
60
62
 
@@ -86,15 +86,17 @@ module Discharger
86
86
  end
87
87
 
88
88
  def set_db_name(db_config)
89
- if db_config["name"] && !ENV["DB_NAME"]
90
- container_name = db_config["name"].to_s
91
- db_name = container_name.sub(/^db-/, "")
89
+ return if db_config["db_name"] == false
90
+
91
+ container_name = db_config["name"].to_s
92
+ db_name = (db_config["db_name"] || container_name.sub(/^db-/, "")).to_s
93
+ return if db_name.empty?
94
+
95
+ if ENV["DB_NAME"]
96
+ warn_if_mismatch("DB_NAME", ENV["DB_NAME"], db_name)
97
+ else
92
98
  ENV["DB_NAME"] = db_name
93
99
  puts " Setting DB_NAME=#{db_name} from config/setup.yml (container: #{container_name})"
94
- elsif ENV["DB_NAME"]
95
- container_name = db_config["name"].to_s
96
- expected_db_name = container_name.sub(/^db-/, "")
97
- warn_if_mismatch("DB_NAME", ENV["DB_NAME"], expected_db_name)
98
100
  end
99
101
  end
100
102
 
@@ -1,3 +1,3 @@
1
1
  module Discharger
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -22,18 +22,31 @@ unless ENV["DISCHARGER_SETUP_BUNDLED"]
22
22
  nil # reported by Discharger::Setup on the second pass
23
23
  end
24
24
  return if source.to_s.empty?
25
- unless `gh auth status 2>&1`.include?("read:packages")
26
- warn "Skipping #{source} credentials: the gh token lacks read:packages (gh auth refresh -s read:packages)"
27
- return
28
- end
29
25
 
30
26
  username = `gh api user --jq .login 2>/dev/null`.strip
31
27
  token = `gh auth token 2>/dev/null`.strip
32
28
  return if username.empty? || token.empty?
29
+ unless source_confirms_token?(source, username, token)
30
+ warn "Leaving bundler credentials for #{source} alone: it did not accept the gh token (gh auth refresh -s read:packages)"
31
+ return
32
+ end
33
33
 
34
34
  system("bundle", "config", "set", "--local", source, "#{username}:#{token}", out: File::NULL, err: File::NULL)
35
35
  end
36
36
 
37
+ def source_confirms_token?(source, username, token)
38
+ require "net/http"
39
+ uri = URI.join("#{source.chomp("/")}/", "versions")
40
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: 5, read_timeout: 10) do |http|
41
+ request = Net::HTTP::Get.new(uri)
42
+ request.basic_auth(username, token)
43
+ http.request(request)
44
+ end
45
+ !%w[401 403].include?(response.code)
46
+ rescue
47
+ false
48
+ end
49
+
37
50
  unless system("bundle", "check", out: File::NULL, err: File::NULL)
38
51
  store_github_packages_credentials
39
52
  system("bundle", "install") || abort(<<~MSG)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discharger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay