Skip to content

Commit

Permalink
docs: improve build (#3674)
Browse files Browse the repository at this point in the history
- generate releases.json et al on our github actions workflow
- use those when building and also on our `run` script
- new releases will dispatch the workflow so it re-generates the needed
files

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Dec 29, 2022
1 parent 2ae0eaf commit 232c982
Show file tree
Hide file tree
Showing 12 changed files with 1,792 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Expand Up @@ -7,3 +7,5 @@

www/docs/static/schema.json linguist-generated=true
www/docs/static/schema-pro.json linguist-generated=true
www/docs/static/releases.json linguist-generated=true
www/docs/static/releases-pro.json linguist-generated=true
2 changes: 2 additions & 0 deletions .github/workflows/generate.yml
Expand Up @@ -9,6 +9,7 @@ on:
- pkg/config/config.go
- CONTRIBUTING.md
- USERS.md
workflow_dispatch:

permissions:
contents: read
Expand All @@ -28,6 +29,7 @@ jobs:
cache: true
- uses: arduino/setup-task@d665c6beebae46ff3f699d7b2fd3f1959de7153c # v1
- run: task docs:generate
- run: task docs:releases
- run: task schema:generate
- uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a # v4
with:
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -13,12 +13,21 @@ permissions:
packages: write

jobs:
trigger-generate:
runs-on: ubuntu-latest
needs: [ goreleaser ]
steps:
- uses: benc-uk/workflow-dispatch@v1
with:
repo: goreleaser/goreleaser
ref: main
token: ${{ secrets.GH_PAT }}
workflow: generate.yml
goreleaser-check-pkgs:
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
needs:
- goreleaser
needs: [ goreleaser ]
if: github.ref == 'refs/heads/main'
strategy:
matrix:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -6,7 +6,6 @@ goreleaser
debug.test
snap.login
site/
www/docs/static/releases*.json
.vercel
completions/
.vscode/
Expand Down
10 changes: 10 additions & 0 deletions Taskfile.yml
Expand Up @@ -94,6 +94,16 @@ tasks:
- www/docs/eula.md
- www/docs/security.md

docs:releases:
desc: Generate docs
cmds:
- ./scripts/get-releases.sh
generates:
- www/docs/static/releases.json
- www/docs/static/releases-pro.json
- www/docs/static/latest
- www/docs/static/latest-pro

docs:imgs:
desc: Download and resize images
cmds:
Expand Down
17 changes: 11 additions & 6 deletions scripts/get-releases.sh
Expand Up @@ -15,18 +15,23 @@ generate() {
last_page="$(get_last_page "$url")"
tmp="$(mktemp -d)"

for i in $(seq 1 "$last_page"); do
for i in $(seq -w 1 "$last_page"); do
echo "page: $i"
curl -H "Authorization: Bearer $GITHUB_TOKEN" -sSf "$url?page=$i" | jq 'map({tag_name: .tag_name})' >"$tmp/$i.json"
done

if test "$last_page" -eq "1"; then
cp -f "$tmp"/1.json "$file"
else
jq --compact-output -s 'add' "$tmp"/*.json >"$file"
fi
jq -s 'add' "$tmp"/*.json >"$file"
du -hs "$file"
}

latest() {
local url="$1"
local file="$2"
curl -sfL "$url/latest" | jq -r ".tag_name" >"$file"
du -hs "$file"
}

latest "https://api.github.com/repos/goreleaser/goreleaser/releases" "www/docs/static/latest"
latest "https://api.github.com/repos/goreleaser/goreleaser-pro/releases" "www/docs/static/latest-pro"
generate "https://api.github.com/repos/goreleaser/goreleaser/releases" "www/docs/static/releases.json"
generate "https://api.github.com/repos/goreleaser/goreleaser-pro/releases" "www/docs/static/releases-pro.json"
3 changes: 1 addition & 2 deletions scripts/pages/build.sh
Expand Up @@ -6,8 +6,7 @@ pip install --upgrade pip
pip install -U mkdocs-material mkdocs-redirects mkdocs-minify-plugin lunr

# prepare
./scripts/get-releases.sh
version="$(curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/goreleaser/goreleaser/releases/latest" | jq -r '.tag_name')"
version="$(cat ./www/docs/static/latest)"
sed -s'' -i "s/__VERSION__/$version/g" www/docs/install.md

# build
Expand Down
1 change: 1 addition & 0 deletions www/docs/static/latest
@@ -0,0 +1 @@
v1.14.0
1 change: 1 addition & 0 deletions www/docs/static/latest-pro
@@ -0,0 +1 @@
v1.14.0-pro
221 changes: 221 additions & 0 deletions www/docs/static/releases-pro.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 232c982

Please sign in to comment.