Skip to content

Commit

Permalink
Automate releases
Browse files Browse the repository at this point in the history
  • Loading branch information
glacials committed Nov 1, 2020
1 parent b6f33fa commit 35e59dd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
8 changes: 7 additions & 1 deletion .yourbase.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
dependencies:
build:
- node:12.19.0
- ruby:2.7.2

build_targets:
- name: default
commands:
- gem build friendly_uuid
- gem install ./friendly_uuid-*.gem
- name: release
commands:
- gem install bundler
- bash release.sh

exec:
environment:
Expand All @@ -16,3 +19,6 @@ ci:
builds:
- name: default
build_target: default
- name: release
build_target: release
when: tagged IS true
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,33 @@ problems:
- Where should `twos.dev/users/a` lead now?

To address this nuance, FriendlyUUID cleverly truncates URLs _past_
uniqueness. It truncates URLs _as long as the URL remains the eldest of its
uniqueness siblings_.
uniqueness. It keeps truncating characters _as long as the URL remains the
eldest among its collisions_.

In other words, after the above example, `A`'s URL continues to be
`twos.dev/users/a`, because when its UUID is truncated to `a` it remains the
_eldest of all records whose UUIDs start with `a`_.

And when `twos.dev/users/a` is accessed, FriendlyUUID knows that the record
being asked for is the _eldest record that starts with `a`_.
being asked for is the _eldest record_ that starts with `a`.

With this tweak, records always have the shortest possible URL, their URLs
never change, and one URL always points to one record—all conventional rules
about URLs are followed.
about URLs are followed, and no extra state was stored!

[2]: https://www.w3.org/Provider/Style/URI

#### Disadvantages
There are two disadvantages to this approach.

As with many stateless algorithms, you pay in machinepower. In this case, the
1. As with many stateless algorithms, you pay in machinepower. In this case, the
queries to discover the shortest-possible URL are quite expensive compared to
O(1) lookups. (The query to discover a record _given_ a URL remains cheap.)

As well, the hard removal of the `A` record in the example above will cause
`twos.dev/users/a` to point to `B`, rather than to 404 as a user might
expect. This can be worked around by soft-deleting records rather than
hard-deleting them.
2. The hard removal of `A` in the above example will cause `twos.dev/users/a`
to point to `B`, rather than to 404 as a user might expect. This can be
worked around by choosing to soft-delete records whenever you would normally
hard-delete them.

### Why use UUIDs?
There are a few of reasons you might want to use UUIDs as primary keys over
Expand Down Expand Up @@ -130,16 +130,25 @@ is still considered a valid "shortening" of itself.
This will mean that each resource may have multiple valid URLs. FriendlyUUID
will never change the URL it generates for a given resource, but if you have
old links floating around in the wild that you want to be canonicalized you
can optionally decide to forward each valid URL to the canonically valid one:
can optionally decide to forward each valid URL to the canonical one:

```ruby
FriendlyUUID.configure do |config|
config.enforce_shortened = true
class UsersController < ApplicationController
before_action :canonicalize_path, only: [:show, :edit]

# ...

private

def canonicalize_path
canonical_path = user_path(@user)
redirect_to canonical_path if canonical_path != request.fullpath
end
end
```

### Why doesn't FriendlyUUID override `id` and `id=` methods?
`id` and `id=` are sensitive methods to override, as they are used as much by
Rails internals as by your application.
Whether or not you take this step, no links will be broken by adding
FriendlyUUID to your app.

## Contributing
See [CONTRIBUTING.md][contributing]
Expand Down
2 changes: 1 addition & 1 deletion friendly_uuid.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "friendly_uuid"
s.version = "0.1.0"
s.version = `git tag --list HEAD | head -n 1`.strip.sub("v", "")
s.date = "2020-10-11"
s.summary = "Make UUIDs pretty enough for use in URLs"
s.description = "FriendlyUUID shortens every UUID to have only as many characters as it needs to be unique."
Expand Down
11 changes: 11 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

mkdir -p ~/.gem
echo "---" > ~/.gem/credentials
echo ":rubygems_api_key: $RUBYGEMS_API_KEY" >> ~/.gem/credentials
echo ":github: Bearer $GITHUB_PERSONAL_ACCESS_TOKEN" >> ~/.gem/credentials
chmod 0600 ~/.gem/credentials
rm -f *.gem
gem build friendly_uuid.gemspec
gem push *.gem
gem push *.gem --key github --host https://rubygems.pkg.github.com/glacials

0 comments on commit 35e59dd

Please sign in to comment.