Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ビルド時のコミットIDなどを公開するように #4815

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions src/client/app/common/views/components/nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<router-link to="/about">{{ $t('@.aboutInstance') }}</router-link>
<i>・</i>
<a :href="repositoryUrl" rel="noopener" target="_blank">{{ $t('repository') }}</a>
<span v-if="commitLabal != null"> (<a v-if="commitUrl != null" :href="commitUrl" rel="noopener" target="_blank">{{ commitLabal }}</a><span v-else >{{ commitLabal }}</span>) </span>
<i>・</i>
<a :href="feedbackUrl" rel="noopener" target="_blank">{{ $t('feedback') }}</a>
<i>・</i>
Expand All @@ -13,19 +14,49 @@
</template>

<script lang="ts">
import Vue from 'vue';
import { defineComponent } from 'vue';
import i18n from '../../../i18n';
import { constants } from '../../../config';
import { constants, commit } from '../../../config';

export default Vue.extend({
export default defineComponent({
i18n: i18n('common/views/components/nav.vue'),
data() {
return {
aboutUrl: `/docs/ja-JP/about`,
repositoryUrl: constants.repositoryUrl,
feedbackUrl: constants.feedbackUrl,
commitLabal: null as string | null,
commitUrl: null as string | null,
}
}
},

mounted() {
this.commitLabal = commit.tag || commit.id?.substring(0, 7) || null;

// find commitUrlBase
let commitUrlBase: string | null = null;

if (typeof this.repositoryUrl === 'string') {
try {
const u = new URL(this.repositoryUrl);
if (u.hostname === 'github.com') {
const m = u.pathname.match(/([/][^/]+[/][^/]+)/) // eg: /user/repo
if (m) {
commitUrlBase = `https://github.com/${m[1]}`; // eg: https://github.com/user/repo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スラッシュ一個多い

}
}
} catch { }
}

// build commitUrl
if (commitUrlBase != null) {
this.commitUrl =
commit.tag ? `${commitUrlBase}/tree/${commit.tag}` :
commit.id ? `${commitUrlBase}/tree/${commit.id}` :
null;
}
},

});
</script>

Expand Down
5 changes: 5 additions & 0 deletions src/client/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ declare const _CONSTANTS_: {
feedbackUrl: string;
};
declare const _VERSION_: string;
declare const _COMMIT_: {
id?: string;
tag?: string;
};
declare const _CODENAME_: string;
declare const _ENV_: string;
declare const _MODS_: {
Expand All @@ -23,5 +27,6 @@ export const locale = JSON.parse(localStorage.getItem('locale'));
export const constants = _CONSTANTS_;
export const version = _VERSION_;
export const codename = _CODENAME_;
export const commit = _COMMIT_;
export const env = _ENV_;
export const mods = _MODS_;
2 changes: 1 addition & 1 deletion src/const.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"repositoryUrl": "https://github.com/mei23/misskey/tree/mei-m544",
"repositoryUrl": "https://github.com/mei23/misskey",
"feedbackUrl": "https://github.com/mei23/misskey/issues/new"
}
14 changes: 14 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

const fs = require('fs');
const child_process = require('child_process');
const webpack = require('webpack');
const rndstr_1 = require('rndstr');
const chalk = require('chalk');
Expand Down Expand Up @@ -32,6 +33,18 @@ const codename = meta.codename;

const version = isProduction ? meta.version : meta.version + '-' + (0, rndstr_1.default)({ length: 8, chars: '0-9a-z' });

const commit = {
id: undefined,
tag: undefined,
};

try {
commit.id = child_process.execSync('git rev-parse HEAD').toString().trim();
commit.tag = child_process.execSync('git tag --points-at HEAD').toString().trim().split('\n')[0];
} catch(e) {
console.warn(e);
}

const postcss = {
loader: 'postcss-loader',
options: {
Expand Down Expand Up @@ -141,6 +154,7 @@ module.exports = {
_CONSTANTS_: JSON.stringify(constants),
_VERSION_: JSON.stringify(version),
_CODENAME_: JSON.stringify(codename),
_COMMIT_: JSON.stringify(commit),
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v && v.meta && v.meta.lang])),
_ENV_: JSON.stringify(process.env.NODE_ENV),
_MODS_: JSON.stringify(mods)
Expand Down
Loading