Skip to content

Commit

Permalink
build: refactor handling of version (#1359)
Browse files Browse the repository at this point in the history
* build: refactor handling of version

* lint installer

* update pre commit

* fixup

* move validate input

* add v prefix in github release
  • Loading branch information
Thykof authored May 17, 2024
1 parent 9dc70b0 commit 38919f7
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 28 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
inputs:
tag_name:
type: string
description: 'The tag name of the release without v prefix'

env:
VERSION: ${{ inputs.tag_name }}
Expand Down Expand Up @@ -109,11 +110,6 @@ jobs:
run: |
export VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')-dev
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set Version
if: ${{ env.VERSION != '' }}
run: |
VERSION=$(echo "${{ env.VERSION }}" | sed 's/^v//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Sync clock
run: sudo sntp -sS time.windows.com # https://github.com/actions/runner/issues/2996#issuecomment-1833103110
- name: Download MassaStation Package
Expand Down Expand Up @@ -156,46 +152,38 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Fetch all git tags
run: git fetch --prune --unshallow --tags

- name: Set Version
if: ${{ env.VERSION == '' }}
shell: bash
run: |
export VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Download MassaStation
uses: actions/download-artifact@v3
with:
name: massastation_windows_amd64_bin

- name: Rename MassaStation binary
run: mv ../massastation_windows_amd64.exe massastation.exe

- name: Build Installer
run: python windows/build_installer.py
env:
VERSION: ${{ env.VERSION }}

- name: Sign Windows binary
uses: ./.github/actions/sign-file
with:
file: installer/massastation_$(echo ${{ env.VERSION }} | sed 's/^v//')_amd64.msi
file: installer/massastation_${{ env.VERSION }}_amd64.msi
name: "Massa Station"
GCP_PEM_KEY: ${{ vars.GCP_PEM_KEY }}
GCP_KEYSTORE_ID: ${{ vars.GCP_KEYSTORE_ID }}
GCP_KEY_ALIAS: ${{ vars.GCP_KEY_ALIAS }}
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
GCP_SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}

- name: Upload Installer
uses: actions/upload-artifact@v3
with:
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release workflow
on:
workflow_dispatch:
inputs:
release-version:
tag_name:
description: "Version to produce"
required: true
type: string
Expand All @@ -24,11 +24,23 @@ on:
default: true

jobs:
validate-input:
name: if tag_name is provided it must not start with "v"
runs-on: ubuntu-latest
steps:
- name: Check if tag_name starts with "v"
run: |
if [[ "${{ github.event.inputs.tag_name }}" == v* ]]; then
echo "tag_name starts with v"
exit 1
fi
build-release:
needs: validate-input
uses: ./.github/workflows/build.yml
secrets: inherit
with:
tag_name: ${{ github.event.inputs.release-version }}
tag_name: ${{ github.event.inputs.tag_name }}

create-release:
name: Release
Expand All @@ -40,7 +52,7 @@ jobs:
- name: Create release and upload binaries
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ inputs.release-version }}
tag_name: v${{ inputs.tag_name }}
draft: ${{ inputs.release-as-draft }}
prerelease: ${{ inputs.release-as-prerelease }}
generate_release_notes: ${{ inputs.generate-release-notes }}
Expand Down
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ tasks:

generate:
cmds:
- task: generate-dirs
- cmd: go generate ./...
- task: generate-dirs
- cmd: go generate ./...

test:
cmds:
Expand Down
2 changes: 1 addition & 1 deletion installer/deb/create_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ EOF
# Check if $VERSION is set and set $PKGVERSION to $VERSION.
if [ ! -z "$VERSION" ]; then
# Remove the `v` prefix from the version.
PKGVERSION=$(echo $VERSION | sed 's/^v//')
PKGVERSION=$VERSION
else # If $VERSION is not set, use the latest git tag followed by `-dev`
PKGVERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')-dev
fi
Expand Down
2 changes: 1 addition & 1 deletion installer/macos/create_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fi
# Check if $VERSION is set and set $PKGVERSION to $VERSION.
if [ ! -z "$VERSION" ]; then
# Remove the `v` prefix from the version.
PKGVERSION=$(echo $VERSION | sed 's/^v//')
PKGVERSION=$VERSION
else # If $VERSION is not set, use the latest git tag followed by `-dev`
PKGVERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')-dev
fi
Expand Down
7 changes: 1 addition & 6 deletions installer/windows/build_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import argparse
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -74,7 +73,7 @@ def build_massastation():
"go",
"build",
"-ldflags",
f"-X github.com/massalabs/station/int/config.Version={VERSION}",
f"-X github.com/massalabs/station/int/config.Version=v{VERSION}",
"-o",
"massastation.exe",
"../cmd/massastation/"
Expand Down Expand Up @@ -439,16 +438,12 @@ def install_dependencies():
capture_output=True,
text=True,
).stdout.strip()
VERSION = re.sub(r"^v", "", VERSION)
except subprocess.CalledProcessError as processErr:
print("Error getting version: ", processErr)
sys.exit(1)
except Exception as gitErr:
print("Error getting version: ", gitErr)
sys.exit(1)
else:
# Remove the "v" from the version if it exists
VERSION = re.sub(r"^v", "", VERSION)

if not sys.platform.startswith("win"):
if not args.force_build:
Expand Down
2 changes: 1 addition & 1 deletion tasks/Taskfile_internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tasks:
- cmd: go build {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}{{.BIN_EXT}} ./cmd/massastation/main.go
vars:
# We need this check for nil and empty string because a simple check for empty string doesn't work as expected
VERSION_FLAG: '{{if ne .VERSION nil}}{{if ne .VERSION ""}}-X github.com/massalabs/station/int/config.Version={{.VERSION}}{{end}}{{end}}'
VERSION_FLAG: '{{if ne .VERSION nil}}{{if ne .VERSION ""}}-X github.com/massalabs/station/int/config.Version=v{{.VERSION}}{{end}}{{end}}'
BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production {{end}}-ldflags="{{.VERSION_FLAG}}{{if eq .PRODUCTION "true"}} -w -s{{end}}"'
BIN_EXT: '{{if eq .OS "windows"}}.exe{{end}}'
env:
Expand Down
3 changes: 3 additions & 0 deletions web/massastation/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

cd web/massastation && npx lint-staged

0 comments on commit 38919f7

Please sign in to comment.