Skip to content

Commit 1e89e83

Browse files
author
Felix Kleinekathöfer
committed
Publish the hompage as a docker image and updated more scripts (#36)
* Docker * Actions * Fixed docker tag * TestPyPi * Use cache in docker publishing * Made list-translations branch specific * Fixed list-translations * Bumped version * Fix exiting on invalid branch * Bumped version * Fixed some languages * Fix for cldr-localenames-modern * Try to fix this hell * Debug * This is driving me crazy * Another fix * Adding it would be better * Removed legacy versions * Suppress warnings * Changed name of flag and disables caching of docker layers * Remove debug and changed repo * Set correct tags to docker image
1 parent 2a1f7ed commit 1e89e83

File tree

18 files changed

+398
-213
lines changed

18 files changed

+398
-213
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Build
5050
run: npm run build
5151

52-
publish:
52+
publish-pypi:
5353
runs-on: ubuntu-latest
5454
needs: build
5555
if: startsWith(github.ref, 'refs/tags')
@@ -72,7 +72,7 @@ jobs:
7272
- name: Setup Node.js
7373
uses: actions/setup-node@v1
7474
with:
75-
node-version: 14
75+
node-version: 14
7676
- name: Setup Python 3.x
7777
uses: actions/setup-python@v2
7878
with:
@@ -95,3 +95,38 @@ jobs:
9595
env:
9696
TWINE_USERNAME: __token__
9797
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
98+
99+
publish-docker:
100+
runs-on: ubuntu-latest
101+
needs: build
102+
if: startsWith(github.ref, 'refs/tags')
103+
steps:
104+
- name: Docker meta
105+
id: docker_meta
106+
uses: crazy-max/ghaction-docker-meta@v1
107+
with:
108+
images: docker-registry.spongepowered.org/sponge-docs-theme
109+
tag-match: \d{1,3}.\d{1,3}.\d{1,3}
110+
tag-match-group: 0
111+
- name: Set up QEMU
112+
uses: docker/setup-qemu-action@v1
113+
- name: Set up Docker Buildx
114+
uses: docker/setup-buildx-action@v1
115+
- name: Login to DockerHub
116+
uses: docker/login-action@v1
117+
with:
118+
registry: docker-registry.spongepowered.org
119+
username: ${{ secrets.SPONGE_MAVEN_REPO_USER }}
120+
password: ${{ secrets.SPONGE_MAVEN_REPO_PASSWORD }}
121+
- name: Build and push
122+
uses: docker/build-push-action@v2
123+
with:
124+
push: true
125+
tags: ${{ steps.docker_meta.outputs.tags }}
126+
labels: ${{ steps.docker_meta.outputs.labels }}
127+
build-args: |
128+
GITHUB_USER=${{ github.actor }}
129+
GITHUB_TOKEN=${{ github.token }}
130+
CROWDIN_TOKEN=${{ secrets.CROWDIN_TOKEN }}
131+
CROWDIN_PROJECT_ID=${{ secrets.CROWDIN_PROJECT_ID }}
132+
BASE_URL=https://docs.spongepowered.org

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,4 @@ jspm_packages
194194
### sponge-docs-theme ###
195195
sponge_docs_theme
196196
!**/js/lib/
197+
docker-compose.yml

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#------- Build
2+
3+
FROM alpine:latest as builder
4+
5+
ARG GITHUB_USER
6+
ARG GITHUB_TOKEN
7+
ARG CROWDIN_TOKEN
8+
ARG CROWDIN_PROJECT_ID
9+
ARG BASE_URL
10+
11+
WORKDIR /app
12+
13+
RUN apk add --no-cache nodejs npm
14+
15+
# This caches node install in docker builds
16+
COPY package.json /app/package.json
17+
RUN npm install
18+
19+
COPY . /app
20+
RUN ./node_modules/.bin/gulp homepage:build
21+
22+
#------- Copy to nginx
23+
24+
FROM nginx:1.19.4-alpine
25+
26+
COPY --from=builder /app/dist/homepage /usr/share/nginx/html

package-lock.json

Lines changed: 33 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
"private": true,
44
"devDependencies": {
55
"autoprefixer": "^10.0.1",
6-
"cldr-core": "^36.0.0",
7-
"cldr-localenames-modern": "^36.0.0",
8-
"cldrjs": "^0.5.0",
6+
"cldr-core": "^37.0.0",
7+
"cldr-localenames-modern": "^37.0.0",
8+
"cldrjs": "^0.5.5",
99
"del": "^6.0.0",
1010
"gulp": "^4.0.2",
1111
"gulp-buble": "^0.9.0",
1212
"gulp-clean-css": "^4.3.0",
1313
"gulp-concat": "^2.6.1",
1414
"gulp-connect": "^5.7.0",
1515
"gulp-htmlmin": "^5.0.1",
16-
"gulp-nunjucks": "^5.0.1",
16+
"gulp-nunjucks": "^5.1.0",
1717
"gulp-postcss": "^9.0.0",
18-
"gulp-sass": "^4.0.1",
18+
"gulp-sass": "^4.1.0",
1919
"gulp-svgmin": "^3.0.0",
2020
"gulp-uglify": "^3.0.0",
2121
"plugin-error": "^1.0.1",
22-
"postcss": "^8.1.0",
22+
"postcss": "^8.1.6",
2323
"request": "^2.79.0",
2424
"request-promise-native": "^1.0.3"
2525
},

src/homepage/data/cldr.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ module.exports.load = () =>
3636

3737
// Load all bundles
3838
for (locale of require('cldr-core/availableLocales').availableLocales.modern) {
39-
Cldr.load(require(`cldr-localenames-modern/main/${locale}/languages`))
39+
// TODO: Remove this when cldr-localenames-modern gets a fix
40+
if(locale !== "ms-ID" && locale !== "sd-Arab") {
41+
Cldr.load(require(`cldr-localenames-modern/main/${locale}/languages`))
42+
}
4043
}
4144

4245
resolve(new CldrLanguages(Cldr))

src/homepage/data/crowdin.js

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,87 @@
11
const rp = require('request-promise-native');
2+
const github = require('./github');
23

3-
const projectIdentifier = 'sponge-docs';
4-
const crowdinApiKey = process.env.CROWDIN_API_KEY;
4+
const crowdinProjectId = process.env.CROWDIN_PROJECT_ID;
5+
const crowdinToken = process.env.CROWDIN_TOKEN;
56

67
const localLanguages = require('./languages');
78

9+
const headers = {
10+
'Authorization': 'Bearer ' + crowdinToken,
11+
'Accept': 'application/json'
12+
};
13+
814
module.exports.getLocaleMappings = () =>
915
rp({
10-
uri: 'https://api.crowdin.com/api/supported-languages?json',
16+
uri: 'https://api.crowdin.com/api/v2/languages?limit=500',
17+
headers: {
18+
'Accept': 'application/json'
19+
},
1120
json: true
1221
}).then((resp) => {
1322
const result = {};
14-
for (language of resp) {
15-
result[localLanguages[language.crowdin_code] || language.crowdin_code] = language.locale
23+
24+
for (language of resp.data) {
25+
const id = localLanguages[language.data.id] || language.data.id;
26+
result[id] = {};
27+
result[id]['name'] = language.data.name;
28+
result[id]['locale'] = language.data.locale;
1629
}
1730
return result;
1831
});
1932

20-
if (crowdinApiKey) {
21-
module.exports.getLanguages = () =>
33+
if (crowdinProjectId && crowdinToken) {
34+
getBranchMappings = () => new Promise((resolve, reject) => {
35+
let crowdinBranches = {};
2236
rp({
23-
uri: `https://api.crowdin.com/api/project/${projectIdentifier}/status`,
24-
qs: {
25-
key: crowdinApiKey,
26-
json: true
27-
},
37+
uri: `https://api.crowdin.com/api/v2/projects/${crowdinProjectId}/branches`,
38+
headers: headers,
2839
json: true
29-
}).then(resp => {
30-
const languages = [];
31-
32-
for (language of resp) {
33-
// Include only languages with at least 5% progress
34-
if (language.translated_progress >= 5 || language.code.startsWith('en-')) {
35-
languages.push({
36-
name: language.name,
37-
code: localLanguages[language.code] || language.code
38-
})
39-
} else {
40-
console.warn(`Skipping ${language.name} with ${language.translated_progress}% completion`)
41-
}
40+
}).then((resp) => {
41+
for (branch of resp.data) {
42+
crowdinBranches[branch.data.name] = branch.data.id;
4243
}
44+
resolve(crowdinBranches);
45+
}).catch(err => reject(err))
46+
})
47+
48+
module.exports.getLanguages = () => new Promise((resolve, reject) => {
49+
Promise.all([github.getVersions(), getBranchMappings()]).then((result) => {
50+
let languages = {};
51+
52+
let promises = [];
53+
54+
result[0].forEach(version => {
55+
promises.push(rp({
56+
uri: `https://api.crowdin.com/api/v2/projects/${crowdinProjectId}/branches/${result[1][version]}/languages/progress`,
57+
headers: headers,
58+
json: true
59+
}).then(resp => {
60+
languages[version] = [];
61+
62+
for (language of resp.data) {
63+
// Include only languages with at least 5% progress
64+
if (language.data.translationProgress >= 5 || language.data.languageId.startsWith('en-')) {
65+
languages[version].push({
66+
id: localLanguages[language.data.languageId] || language.data.languageId
67+
})
68+
} else {
69+
console.warn(`[${version}] Skipping ${language.data.languageId} with ${language.data.translationProgress}% completion`)
70+
}
71+
}
4372

44-
// Sort languages by Crowdin code
45-
languages.sort((a, b) => a.code.localeCompare(b.code));
73+
// Sort languages by language id
74+
languages[version].sort((a, b) => a.id.localeCompare(b.id));
75+
}))
76+
})
4677

47-
return languages;
78+
Promise.all(promises).then(() => {
79+
resolve(languages);
80+
}).catch(err => reject(err))
4881
});
82+
})
4983
} else {
50-
console.warn("CROWDIN_API_KEY is not set; using local test languages");
84+
console.warn("CROWDIN_PROJECT_ID or CROWDIN_TOKEN is not set; using local test data");
5185
module.exports.getLanguages = () =>
5286
new Promise((resolve, reject) => {
5387
try {

0 commit comments

Comments
 (0)