Skip to content

Commit

Permalink
fix: version regression after eae3f91, add test (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Mar 25, 2024
1 parent 44c804d commit e1f14c4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/analyzer_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ jobs:

- name: Run tests
run: v test .

- name: Install v-analyzer
if: runner.os != 'Windows'
run: |
# Build and install v-analyzer at the head ref of the submitted changes.
v run build.vsh
sudo mv ./bin/v-analyzer /usr/local/bin/v-analyzer
v-analyzer --version
- name: Verify version
# TODO: include Windows
if: runner.os != 'Windows'
run: v .github/workflows/version_test.vv
19 changes: 19 additions & 0 deletions .github/workflows/version_test.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import v.vmod

fn test_version() {
if os.getenv('CI') != 'true' {
eprintln('WARNING: expecting usage in combination with CI workflow.')
}

git_ref := os.getenv('GITHUB_WORKFLOW_SHA').trim_space()[..7]
manifest := vmod.decode(@VMOD_FILE)!
assert manifest.name == 'v-analyzer'

// Move out of the project directory to ensure that we exclude the possiblity of
// deriving the commit reference from v-analyzer's directory at program startup.
os.chdir('/tmp/')!
analyzer_version := os.execute_opt('v-analyzer --version')!.output.all_after_last(' ').trim_space()

assert '${manifest.version}.${git_ref}' == analyzer_version
}
10 changes: 8 additions & 2 deletions build.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import os
import cli
import term
import time
import metadata

const bin_path = './bin/v-analyzer' + $if windows { '.exe' } $else { '' }
const build_commit = os.execute('git rev-parse --short HEAD').output.trim_space()
const build_datetime = time.now().format_ss()

enum ReleaseMode {
release
Expand Down Expand Up @@ -58,7 +61,7 @@ fn prepare_output_dir() {
}

fn build(mode ReleaseMode, explicit_debug bool) {
println('Building v-analyzer at commit: ${metadata.build_commit}, build time: ${metadata.build_datetime} ...')
println('Building v-analyzer at commit: ${build_commit}, build time: ${build_datetime} ...')

prepare_output_dir()
println('${term.green('✓')} Prepared output directory')
Expand Down Expand Up @@ -86,9 +89,12 @@ fn build(mode ReleaseMode, explicit_debug bool) {

// main program:

os.setenv('BUILD_DATETIME', build_datetime, true)
os.setenv('BUILD_COMMIT', build_commit, true)

mut cmd := cli.Command{
name: 'v-analyzer-builder'
version: metadata.full_version
version: metadata.manifest.version
description: 'Builds the v-analyzer binary.'
posix_mode: true
execute: fn (_ cli.Command) ! {
Expand Down
7 changes: 2 additions & 5 deletions metadata/metadata.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module metadata
import os
import v.vmod
import v.embed_file
import time

pub const manifest = vmod.decode(@VMOD_FILE) or { panic(err) }
pub const build_commit = os.execute('git rev-parse --short HEAD').output.trim_space()
pub const build_datetime = time.now().format_ss()
pub const build_datetime = $env('BUILD_DATETIME')
pub const build_commit = $env('BUILD_COMMIT')
pub const full_version = manifest.version + '.' + build_commit

struct EmbedFS {
Expand Down Expand Up @@ -35,7 +34,6 @@ pub fn embed_fs() EmbedFS {
files << $embed_file('stubs/compile_time_reflection.v', .zlib)
files << $embed_file('stubs/builtin_compile_time.v', .zlib)
files << $embed_file('stubs/channels.v', .zlib)
files << $embed_file('stubs/README.md', .zlib)
files << $embed_file('stubs/attributes/Deprecated.v', .zlib)
files << $embed_file('stubs/attributes/Table.v', .zlib)
files << $embed_file('stubs/attributes/Attribute.v', .zlib)
Expand All @@ -49,7 +47,6 @@ pub fn embed_fs() EmbedFS {
files << $embed_file('stubs/c_decl.v', .zlib)
files << $embed_file('stubs/errors.v', .zlib)
files << $embed_file('stubs/threads.v', .zlib)
files << $embed_file('v.mod', .zlib)

return EmbedFS{
files: files
Expand Down

0 comments on commit e1f14c4

Please sign in to comment.