Skip to content

Commit 5750d9c

Browse files
authored
Merge pull request #56 from sklevenz/dev
optimize release job
2 parents 07fffaa + 8fe5988 commit 5750d9c

File tree

3 files changed

+24
-76
lines changed

3 files changed

+24
-76
lines changed

.github/workflows/docs.yaml

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77

88
permissions:
99
contents: write
10-
pages: write
11-
id-token: write
1210

1311
jobs:
1412
publish:
@@ -25,79 +23,11 @@ jobs:
2523
- name: Generate OpenAPI Doc
2624
run: make upgrade docs
2725

28-
- name: Determine doc version
29-
id: version
26+
- name: Push to gh-pages branch
3027
run: |
31-
set -euo pipefail
32-
version=$(yq e '.info.version' ./spec/openapi.yaml)
33-
if [[ -z "${version}" || "${version}" == "null" ]]; then
34-
echo "Could not read .info.version from ./spec/openapi.yaml" >&2
35-
exit 1
36-
fi
37-
echo "version=${version}" >> "$GITHUB_OUTPUT"
38-
39-
- name: Publish docs to gh-pages with history
40-
env:
41-
DOC_VERSION: ${{ steps.version.outputs.version }}
42-
run: |
43-
set -euo pipefail
44-
4528
git config --global user.name "github-actions"
4629
git config --global user.email "github-actions@github.com"
47-
48-
# Keep the generated docs from main branch checkout
49-
rm -rf /tmp/generated-docs
50-
mkdir -p /tmp/generated-docs
51-
cp -R ./docs/. /tmp/generated-docs/
52-
53-
# Check if gh-pages exists, if not create it
54-
if git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then
55-
git fetch origin gh-pages:gh-pages
56-
git checkout gh-pages
57-
else
58-
git checkout --orphan gh-pages
59-
git rm -rf . || true
60-
mkdir -p docs
61-
echo "<html><body><p>Initializing gh-pages</p></body></html>" > docs/index.html
62-
git add docs/index.html
63-
git commit -m "Initialize gh-pages"
64-
fi
65-
66-
mkdir -p docs/releases/${DOC_VERSION}
67-
68-
# Copy the generated HTML and any assets into the versioned folder
69-
rm -rf docs/releases/${DOC_VERSION}/*
70-
cp -R /tmp/generated-docs/. docs/releases/${DOC_VERSION}/
71-
72-
# Render the docs index as a simple link list
73-
mkdir -p docs
74-
{
75-
echo '<!doctype html>'
76-
echo '<html>'
77-
echo '<head><meta charset="utf-8"><title>CF API Spec Docs</title></head>'
78-
echo '<body>'
79-
echo '<h1>CF API Spec Docs</h1>'
80-
echo '<ul>'
81-
for d in $(ls -1 docs/releases 2>/dev/null | sort -Vr); do
82-
# Prefer an html entry point if present
83-
if ls "docs/releases/${d}"/*.html > /dev/null 2>&1; then
84-
first_html=$(ls -1 "docs/releases/${d}"/*.html | head -n 1)
85-
rel_path=${first_html#docs/}
86-
echo "<li><a href=\"/${rel_path}\">${d}</a></li>"
87-
else
88-
echo "<li>${d}</li>"
89-
fi
90-
done
91-
echo '</ul>'
92-
echo '</body>'
93-
echo '</html>'
94-
} > docs/index.html
95-
96-
git add -A
97-
if git diff --cached --quiet; then
98-
echo "No changes to publish"
99-
exit 0
100-
fi
101-
102-
git commit -m "Publish docs ${DOC_VERSION}"
103-
git push origin gh-pages
30+
git checkout --orphan gh-pages
31+
git add -f ./docs # Force add the docs folder to the gh-pages branch even if it's in .gitignore file
32+
git commit -m "Publish GitHub Pages"
33+
git push origin gh-pages --force

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ help:
3939
@echo " make ignore-file - Generate Vacuum ignore file from hard mode report"
4040
@echo ""
4141
@echo "Releasing:"
42-
@echo " make release - Release on github (VERSION=0.0.0)"
42+
@echo " make release - Release on github"
4343
@echo " make release-list - List available releases"
4444

4545

scripts/release.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ docs_out="${GEN_DIR}/cf-api-openapi-${tag}.html"
6161
run "Copying release artifacts" cp "${openapi_src}" "${openapi_out}"
6262
run "Copying release artifacts" cp "${docs_src}" "${docs_out}"
6363

64+
print_step "Preparing GitHub release"
65+
66+
echo ""
67+
echo "About to create GitHub release"
68+
echo " Tag: ${tag}"
69+
echo " Target: main"
70+
echo " Title: ${tag}"
71+
echo " Assets:"
72+
echo " ${openapi_out}"
73+
echo " ${docs_out}"
74+
echo ""
75+
76+
read -r -p "Proceed with creating the GitHub release? (y/N): " confirm
77+
if [[ ! "${confirm}" =~ ^[Yy]$ ]]; then
78+
echo "Aborted"
79+
exit 1
80+
fi
81+
6482
print_step "Creating GitHub release ${tag}"
6583

6684
run "gh release create" gh release create "${tag}" "${openapi_out}" "${docs_out}" \

0 commit comments

Comments
 (0)