Skip to content

Commit 4a8f4f4

Browse files
authored
feat: revision date and footer (#44)
* feat: revision date and hash * feat: workflow to create release * feat: different release
1 parent c945868 commit 4a8f4f4

File tree

4 files changed

+209
-2
lines changed

4 files changed

+209
-2
lines changed

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Release on Package Update
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
- release
9+
paths:
10+
- 'package.json'
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Extract version from package.json
22+
id: version
23+
run: |
24+
VERSION=$(jq -r '.version' package.json)
25+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
26+
echo "Extracted version: $VERSION"
27+
28+
- name: Generate release tag and metadata
29+
id: release_info
30+
run: |
31+
VERSION=${{ steps.version.outputs.VERSION }}
32+
COMMIT_HASH=$(git rev-parse --short HEAD)
33+
BRANCH=${{ github.ref_name }}
34+
BUILD_DATE=$(date +'%Y%m%d')
35+
36+
if [[ "$BRANCH" == "release" ]]; then
37+
TAG="v$VERSION"
38+
TITLE="v$VERSION"
39+
NOTES="Release v$VERSION"
40+
IS_PRERELEASE="false"
41+
IS_LATEST="true"
42+
else
43+
TAG="v$VERSION-pre.$BUILD_DATE.$COMMIT_HASH"
44+
TITLE="v$VERSION-pre ($COMMIT_HASH)"
45+
NOTES="Pre-release v$VERSION from branch: $BRANCH"$'\n'"Commit: $COMMIT_HASH"$'\n'"Build Date: $BUILD_DATE"
46+
IS_PRERELEASE="true"
47+
IS_LATEST="false"
48+
fi
49+
50+
echo "TAG=$TAG" >> $GITHUB_OUTPUT
51+
echo "TITLE=$TITLE" >> $GITHUB_OUTPUT
52+
echo "NOTES<<EOF" >> $GITHUB_OUTPUT
53+
echo "$NOTES" >> $GITHUB_OUTPUT
54+
echo "EOF" >> $GITHUB_OUTPUT
55+
echo "IS_PRERELEASE=$IS_PRERELEASE" >> $GITHUB_OUTPUT
56+
echo "IS_LATEST=$IS_LATEST" >> $GITHUB_OUTPUT
57+
echo "Generated tag: $TAG"
58+
59+
- name: Check if release already exists
60+
id: check_release
61+
run: |
62+
TAG=${{ steps.release_info.outputs.TAG }}
63+
if gh release view "$TAG" > /dev/null 2>&1; then
64+
echo "EXISTS=true" >> $GITHUB_OUTPUT
65+
else
66+
echo "EXISTS=false" >> $GITHUB_OUTPUT
67+
fi
68+
env:
69+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Create Release
72+
if: steps.check_release.outputs.EXISTS == 'false'
73+
run: |
74+
TAG=${{ steps.release_info.outputs.TAG }}
75+
TITLE=${{ steps.release_info.outputs.TITLE }}
76+
IS_PRERELEASE=${{ steps.release_info.outputs.IS_PRERELEASE }}
77+
IS_LATEST=${{ steps.release_info.outputs.IS_LATEST }}
78+
79+
CREATE_ARGS="--title '$TITLE'"
80+
81+
if [[ "$IS_PRERELEASE" == "true" ]]; then
82+
CREATE_ARGS="$CREATE_ARGS --prerelease"
83+
fi
84+
85+
if [[ "$IS_LATEST" == "true" ]]; then
86+
CREATE_ARGS="$CREATE_ARGS --latest"
87+
fi
88+
89+
gh release create "$TAG" \
90+
$CREATE_ARGS \
91+
--notes "${{ steps.release_info.outputs.NOTES }}"
92+
env:
93+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/App.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<InsiderBanner />
88
</div>
99
<div>
10-
<ActivityBanner :Enable="true">
10+
<ActivityBanner :Enable="false">
1111
OhMyGPA 论坛试运营! 访问 <a
1212
href="https://ohmygpa.icu/"
1313
target="_blank"
@@ -18,6 +18,7 @@
1818
</div>
1919

2020
<router-view :key="$route.path" class="mt-15 sm:mt-0" />
21+
<Footer />
2122
<v-snackbar
2223
v-model="snackbar.show"
2324
:color="snackbar.color"
@@ -40,6 +41,7 @@
4041
import Header from '@/components/global/Header';
4142
import InsiderBanner from '@/components/global/InsiderBanner';
4243
import ActivityBanner from '@/components/global/ActivityBanner';
44+
import Footer from '@/components/global/Footer';
4345
import useSnackbar from '@/composables/global/useSnackbar';
4446
import { getPreset } from '@/composables/global/useCookie';
4547
import { provide, reactive } from 'vue';
@@ -48,7 +50,7 @@ import MenuSideBar from '@/components/global/MenuSideBar.vue';
4850
4951
export default {
5052
name: 'App',
51-
components: { Header, InsiderBanner, ActivityBanner, MenuSideBar },
53+
components: { Header, InsiderBanner, ActivityBanner, MenuSideBar, Footer },
5254
setup() {
5355
const { snackbar } = useSnackbar();
5456
const global = reactive({

src/components/global/Footer.vue

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<template>
2+
<footer class="footer-container">
3+
<v-divider></v-divider>
4+
<div class="footer-content pt-5">
5+
<div class="footer-text">
6+
<span class="copyright">
7+
&copy; {{ currentYear }} CourseBench. All rights reserved.
8+
</span>
9+
<span class="version-info">
10+
v{{ version }}
11+
<span v-if="buildHash" class="build-hash">
12+
(Build: {{ buildHash }})
13+
</span>
14+
<span v-if="buildDate" class="build-date">
15+
Last build at: {{ buildDate }}
16+
</span>
17+
</span>
18+
</div>
19+
</div>
20+
</footer>
21+
</template>
22+
23+
<script>
24+
export default {
25+
name: 'Footer',
26+
setup() {
27+
const currentYear = new Date().getFullYear();
28+
const version = process.env.VUE_APP_VERSION || '0.1.0';
29+
const buildHash = process.env.VUE_APP_BUILD_HASH || '';
30+
const buildDate = process.env.VUE_APP_BUILD_DATE || '';
31+
32+
return {
33+
currentYear,
34+
version,
35+
buildHash,
36+
buildDate,
37+
};
38+
},
39+
};
40+
</script>
41+
42+
<style scoped>
43+
.footer-container {
44+
padding: 30px 20px;
45+
background-color: #f8f8f9;
46+
text-align: center;
47+
}
48+
49+
.footer-content {
50+
max-width: 1200px;
51+
margin: 0 auto;
52+
}
53+
54+
.footer-text {
55+
display: flex;
56+
flex-direction: column;
57+
gap: 8px;
58+
font-size: 0.875rem;
59+
color: rgba(0, 0, 0, 0.6);
60+
}
61+
62+
.copyright {
63+
font-weight: 500;
64+
}
65+
66+
.version-info {
67+
font-size: 0.8125rem;
68+
color: rgba(0, 0, 0, 0.5);
69+
}
70+
71+
.build-hash {
72+
font-family: monospace;
73+
margin-left: 4px;
74+
}
75+
76+
.build-date {
77+
margin-left: 8px;
78+
}
79+
80+
/* Dark mode support */
81+
@media (prefers-color-scheme: dark) {
82+
.footer-container {
83+
background-color: #222222;
84+
}
85+
86+
.footer-text {
87+
color: rgba(255, 255, 255, 0.7);
88+
}
89+
90+
.version-info {
91+
color: rgba(255, 255, 255, 0.5);
92+
}
93+
}
94+
</style>

vue.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ const productionGzipExtensions = /\.(js|css|json|md|html|ico)(\?.*)?$/i;
33
const path = require('path');
44
const process = require('process');
55
const fs = require('fs');
6+
const { execSync } = require('child_process');
7+
const packageJson = require('./package.json');
8+
9+
// Generate build hash (first 8 characters of git commit hash)
10+
let buildHash = '';
11+
try {
12+
buildHash = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim().substring(0, 8);
13+
} catch (e) {
14+
buildHash = 'unknown';
15+
}
16+
17+
// Generate build date
18+
const buildDate = new Date().toISOString().split('T')[0];
19+
20+
// Set environment variables
21+
process.env.VUE_APP_VERSION = packageJson.version;
22+
process.env.VUE_APP_BUILD_HASH = buildHash;
23+
process.env.VUE_APP_BUILD_DATE = buildDate;
624

725
module.exports = {
826
productionSourceMap: false,

0 commit comments

Comments
 (0)