Skip to content

Commit

Permalink
Merge branch 'main' into mime_from_contenttype
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Nov 5, 2024
2 parents d0ac067 + c3ce1f5 commit 6f85742
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 31 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Invalidations

on:
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: always.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
evaluate:
# Only run on PRs to the default branch.
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
if: github.base_ref == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@v2
with:
version: 'lts'
- uses: actions/checkout@v4
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_pr

- uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_default

- name: Report invalidation counts
run: |
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
- name: Check if the PR does increase number of invalidations
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
run: exit 1
43 changes: 26 additions & 17 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
# This GitHub action checks whether a new version of this package
# has been registred in the official registry.
# If so, it creates a new _release_:
# https://github.com/JuliaPluto/PlutoSliderServer.jl/releases

name: TagBot

on:
issue_comment:
types:
- created
workflow_dispatch:
schedule:
- cron: '0 * * * *'

inputs:
lookback:
default: "3"
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.actor == 'JuliaTagBot'
runs-on: [ubuntu-latest]
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
lookback: 30
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
ssh: ${{ secrets.DOCUMENTER_KEY }}
# ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }}
6 changes: 3 additions & 3 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
# continue-on-error: true
strategy:
matrix:
julia-version: ['1.3', '1']
julia-version: ['1.3', '1.6', '1.10', '1']
os: [ubuntu-latest, windows-latest]

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "MIMEs"
uuid = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "Takafumi Arakaki <[email protected]>", "Thibaut Lienart <[email protected]>"]
version = "0.1.3"
version = "1.0.0"

[compat]
julia = "1.3"
Expand Down
1 change: 1 addition & 0 deletions mimedb/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
2 changes: 1 addition & 1 deletion mimedb/mimedb.jlon

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions mimedb/update.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()

import JSON
import Downloads: download
import OrderedCollections: OrderedDict

version = v"1.52.0"
version = v"1.53.0"

mdb = joinpath(@__DIR__, "mimedb.jlon")

_source_preference = ("nginx", "apache", nothing, "iana")



unorder(d::AbstractDict) = Dict(k => unorder(v) for (k, v) in d)
unorder(d::AbstractVector) = map(unorder, d)
unorder(x::Any) = x


# Check if there's a new version and alert the user, don't automatically take
# it as the format of the JSON may change
begin
Expand All @@ -34,11 +43,8 @@ end
begin
@info "📩 downloading the DB..."
url = "https://cdn.jsdelivr.net/gh/jshttp/mime-db@$(version)/db.json"
d = JSON.parse(read(download(url), String))
d = JSON.parse(read(download(url), String); dicttype=OrderedDict)
_mimedb = let
# https://github.com/jshttp/mime-db/issues/194
d["text/javascript"], d["application/javascript"] = d["application/javascript"], d["text/javascript"]

d["text/julia"] = Dict{String,Any}(
"charset" => "UTF-8",
"compressible" => true,
Expand All @@ -56,17 +62,19 @@ begin
# Ported straight from https://github.com/jshttp/mime-types/blob/2.1.35/index.js#L154
for (mime_str, val) in _mimedb
mime = mime_str
@assert mime isa String

exts = get(val, "extensions", nothing)
if exts === nothing
continue
end
@assert exts isa Vector
_mime2ext[mime] = exts

src = get(val, "source", nothing)
for ex in exts
if haskey(_ext2mime, ex)
other_src = get(_mimedb[identity(_ext2mime[ex])], "source", nothing)
other_src = get(_mimedb[_ext2mime[ex]], "source", nothing)

from = findfirst(isequal(other_src), _source_preference)
to = findfirst(isequal(src), _source_preference)
Expand All @@ -75,7 +83,7 @@ begin
!(_ext2mime[ex] isa MIME"application/octet-stream") &&
(
from > to ||
(from == to && startswith(identity(_ext2mime[ex]), "application/")
(from == to && startswith(_ext2mime[ex], "application/")
)
)
)
Expand All @@ -86,11 +94,16 @@ begin
_ext2mime[ex] = mime
end
end

# Changing the default mime for the .mp4 extension to video/mp4
# this is the more common and expected type, and makes the assumption that the file contains video
# The RFC https://www.rfc-editor.org/rfc/rfc4337.txt does not specify a **default** mime type for mp4 files, it should depend on content. application/mp4 should be used for mp4 files without video/audio content, so it is not necessarily a better default than video/mp4.
_ext2mime["mp4"] = "video/mp4"

@info "✏ writing to file $mdb..."
open(mdb, "w") do f
write(f, string(
(_mimedb, _ext2mime, _mime2ext)
(unorder(_mimedb), _ext2mime, _mime2ext)
)
)
end
Expand Down
1 change: 1 addition & 0 deletions src/MIMEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Turn a MIME into a Content-Type header value, which might include the `charset`
```julia
contenttype_from_mime(MIME"application/json"()) == "application/json; charset=utf-8"
contenttype_from_mime(MIME"application/x-bogus"()) == "application/x-bogus"
contenttype_from_mime(mime_from_extension(".png", MIME"application/octet-stream"())) == "image/png"
```
# See also:
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sub(s) = SubString(s, 1)

@test contenttype_from_mime(MIME"application/json"()) == "application/json; charset=utf-8"
@test contenttype_from_mime(MIME"application/x-bogus"()) == "application/x-bogus"
@test contenttype_from_mime(mime_from_extension(".png", MIME"application/octet-stream"())) == "image/png"


@test mime_from_contenttype("application/json; charset=utf-8") == MIME"application/json"()
Expand Down Expand Up @@ -63,8 +64,10 @@ const mdn = Dict(
".mjs" => "text/javascript",
".mp3" => "audio/mpeg",
".mp4" => "video/mp4",
".mp4s" => "application/mp4",
".mpeg" => "video/mpeg",
".ogx" => "application/ogg", ".otf" => "font/otf",
".ogx" => "application/ogg",
".otf" => "font/otf",
".png" => "image/png",
".pdf" => "application/pdf",
".rtf" => "application/rtf",
Expand Down

0 comments on commit 6f85742

Please sign in to comment.