Production Release Pipeline #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Production Release Pipeline | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_version: | |
| description: "Enter version (e.g., 1.2.3). Leave empty for auto patch bump." | |
| required: false | |
| default: "" | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create GitHub App Token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ vars.RUBRION_APP_ID }} | |
| private-key: ${{ secrets.RUBRION_APP_SECRET }} | |
| - name: Set Git User Identity | |
| run: | | |
| git config --global user.name "Rubrion" | |
| git config --global user.email "rubrion[bot]@users.noreply.github.com" | |
| - name: Checkout Develop Branch | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: develop | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Ensure Develop is Up to Date | |
| run: | | |
| git fetch origin develop | |
| git checkout develop | |
| git pull origin develop | |
| - name: Check if Main Branch Exists and Merge | |
| run: | | |
| if git ls-remote --heads origin main | grep main; then | |
| echo "Main branch exists, proceeding with merge" | |
| git checkout main || git checkout -b main | |
| git merge --no-ff develop -m "chore: merge develop into main for release v${VERSION}" | |
| else | |
| echo "Main branch does not exist, creating from develop" | |
| git checkout -b main | |
| fi | |
| git push -u origin main | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| - name: Determine Release Version | |
| id: version | |
| run: | | |
| if [ -n "${{ github.event.inputs.release_version }}" ]; then | |
| VERSION=${{ github.event.inputs.release_version }} | |
| else | |
| LAST_TAG=$(git tag --sort=-v:refname | head -n 1 | sed 's/v//') | |
| IFS='.' read -r major minor patch <<< "$LAST_TAG" | |
| VERSION="$major.$minor.$((patch + 1))" | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "Release version set to $VERSION" | |
| - name: Verify Version in Code | |
| run: | | |
| VERSION_IN_CODE=$(grep "CurrentVersion =" internal/commands/version.go | awk -F'"' '{print $2}') | |
| echo "Version in code: $VERSION_IN_CODE" | |
| echo "Expected version: $VERSION" | |
| if [ "$VERSION_IN_CODE" != "$VERSION" ]; then | |
| echo "ERROR: Version mismatch detected!" | |
| echo "The version in internal/commands/version.go ($VERSION_IN_CODE) does not match the release version ($VERSION)." | |
| echo "Please update the CurrentVersion in internal/commands/version.go to $VERSION and run the workflow again." | |
| exit 1 | |
| else | |
| echo "Version check passed: Code version matches release version." | |
| fi | |
| - name: Generate Changelog | |
| run: | | |
| npx conventional-changelog-cli -p angular -o docs/CHANGELOG.md | |
| git add docs/CHANGELOG.md | |
| git commit -m "docs: release v${VERSION} [skip ci]" | |
| git push origin main | |
| - name: Create Git Tag | |
| run: | | |
| git tag "v${VERSION}" | |
| git push origin --tags | |
| - name: Set Up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.23 | |
| - name: Build Cross-Platform Binaries | |
| run: | | |
| if [ -z "${{ vars.PROJECT_NAME }}" ]; then | |
| PROJECT_NAME="enemeter-data-processing" | |
| echo "Using default project name: $PROJECT_NAME" | |
| else | |
| PROJECT_NAME="${{ vars.PROJECT_NAME }}" | |
| echo "Using project name from settings: $PROJECT_NAME" | |
| fi | |
| go mod tidy | |
| echo "Building CLI for version $VERSION" | |
| make build-all VERSION=$VERSION | |
| - name: Create GitHub Release | |
| run: | | |
| PROJECT_NAME="${{ vars.PROJECT_NAME }}" | |
| if [ -z "$PROJECT_NAME" ]; then | |
| PROJECT_NAME="enemeter-data-processing" | |
| fi | |
| gh release create "v${VERSION}" \ | |
| --title "Release v${VERSION}" \ | |
| --notes-file docs/CHANGELOG.md \ | |
| dist/$PROJECT_NAME-linux dist/$PROJECT_NAME.exe dist/$PROJECT_NAME-mac | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} |