Skip to content

Commit

Permalink
Merge branch 'main' into fix/zero-based-hdm-range
Browse files Browse the repository at this point in the history
  • Loading branch information
HJ-Fan committed Oct 8, 2024
2 parents e561531 + 88fe381 commit 0af475e
Show file tree
Hide file tree
Showing 50 changed files with 2,395 additions and 1,127 deletions.
70 changes: 0 additions & 70 deletions .github/workflows/publish.yml

This file was deleted.

109 changes: 109 additions & 0 deletions .github/workflows/release-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Release and Publish

on:
workflow_dispatch:

env:
LAST_VERSION:
NEXT_VERSION:
PUBLISH_IMAGE:
IMAGE_REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}

jobs:
release-and-publish:
permissions:
contents: write # to be able to publish a GitHub release
packages: write # to be able to upload a registry image
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup npm\npx
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install semantic-release and dependencies
run: npm install semantic-release@v24 @semantic-release/exec@v6 -D conventional-changelog-conventionalcommits@v8

# Need the dry-run to get the next version # BEFORE running the formal semantic release
- name: Run Semantic Release (dry-run)
run: npx semantic-release --dry-run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Retrieve Semantic Release Dry-Run Output
run: |
echo 'LAST_VERSION = "${{ env.LAST_VERSION }}"'
echo 'NEXT_VERSION = "${{ env.NEXT_VERSION }}"'
if [ "${{ env.LAST_VERSION }}" != "${{ env.NEXT_VERSION }}" ]; then
echo "PUBLISH_IMAGE=true" >> $GITHUB_ENV
echo 'PUBLISH_IMAGE = "true"'
else
echo "PUBLISH_IMAGE=false" >> $GITHUB_ENV
echo 'PUBLISH_IMAGE = "false"'
fi
# Update source code files where version is currently hardcoded BEFORE the real semantic-release is executed.
# This allows the release assets to be created using correctly versioned source code files.
# This source code version update is also leveraged during docker image creation.
- name: Update Local VERSION file (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
run: |
sed -i 's/1\.x\.x/${{ env.NEXT_VERSION }}/g' ./cmd/cfm-cli/cmd/root.go
sed -i 's/1\.x\.x/${{ env.NEXT_VERSION }}/g' ./cmd/cfm-service/main.go
sed -i 's/1\.x\.x/${{ env.NEXT_VERSION }}/g' ./cmd/cxl-host/service/parameters.go
sed -i 's/1\.x\.x/${{ env.NEXT_VERSION }}/g' ./webui/package.json
sed -i 's/1\.x\.x/${{ env.NEXT_VERSION }}/g' ./webui/package-lock.json
# Test build to just make sure that it runs.
#TODO: Remove once CI\CD matures.
- name: Test Docker Build Local (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
run: |
docker build --no-cache -t ${{ env.CFM_TEST_IMAGE }} -f ./docker/Dockerfile .
docker rmi ${{ env.CFM_TEST_IMAGE }}
env:
CFM_TEST_IMAGE: cfm-test-image:v${{ env.NEXT_VERSION }}

# Manually create separate GitHub Release assets for upload using source code with updated version number.
- name: Create Release Assets for Semantic Release (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
run: |
mkdir -p /tmp/dist
cd ..
cp -r ./cfm ./${{ env.ARCHIVE_FOLDER }}
zip -r /tmp/dist/${{ env.ARCHIVE_NAME }}.zip ${{ env.ARCHIVE_FOLDER }} -x "./${{ env.ARCHIVE_FOLDER }}/.git/*" -x "./${{ env.ARCHIVE_FOLDER }}/node_modules/*"
tar --exclude='./${{ env.ARCHIVE_FOLDER }}/.git' --exclude='./${{ env.ARCHIVE_FOLDER }}/node_modules' -czf /tmp/dist/${{ env.ARCHIVE_NAME }}.tar.gz ${{ env.ARCHIVE_FOLDER }}
cd cfm
env:
ARCHIVE_FOLDER: cfm-v${{ env.NEXT_VERSION }}
ARCHIVE_NAME: cfm-${{ env.NEXT_VERSION }}-versioned

- name: Run Semantic Release (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Container Registry Login (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
uses: docker/login-action@v3
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Image Build (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
run: docker build --no-cache -t ${{ env.CFM_NEXT_VERSION }} -t ${{ env.CFM_LATEST_VERSION }} -f ./docker/Dockerfile .
env:
CFM_NEXT_VERSION: ${{ env.IMAGE_NAME }}:v${{ env.NEXT_VERSION }}
CFM_LATEST_VERSION: ${{ env.IMAGE_NAME }}:latest

- name: Docker Image Publish (Conditional)
if: ${{ env.PUBLISH_IMAGE == 'true' }}
run: docker push --all-tags ${{ env.IMAGE_NAME }}
26 changes: 0 additions & 26 deletions .github/workflows/release.yml

This file was deleted.

119 changes: 119 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
branches: ['main']
ci: true
debug: true
dryRun: false
preset: 'conventionalcommits'

# Specify plugins to override semantic-release defaults
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/github"
- "@semantic-release/exec"

verifyConditions:
- '@semantic-release/github'

analyzeCommits:
- path: '@semantic-release/commit-analyzer'
# Determine the type of release by analyzing commits with conventional-changelog
releaseRules:
- breaking: true
release: major
- type: build # Changes that affect the build system or external dependencies
# (example scopes: gulp, broccoli, npm)
release: patch
- type: chore # Other changes that don't modify src or test files
release: false
- type: ci # Changes to our CI configuration files and scripts
release: false
- type: docs # Documentation only changes
release: patch
- type: feat # A new feature
release: minor
- type: fix # A bug fix
release: patch
- type: perf # A code change that improves performance
release: patch
- type: refactor # A code change that neither fixes a bug nor adds a feature
release: false
- type: revert # Reverts a previous commit
release: patch
- type: style # Changes that do not affect the meaning of the code
# (white-space, formatting, missing semi-colons, etc)
release: false
- type: test # Adding missing tests or correcting existing tests
release: false

verifyRelease:
- path: '@semantic-release/exec'
verifyReleaseCmd: 'echo "LAST_VERSION=${lastRelease.version}" >> $GITHUB_ENV && echo "NEXT_VERSION=${nextRelease.version}" >> $GITHUB_ENV'

generateNotes:
- path: '@semantic-release/release-notes-generator'
# writerOpts:
# groupBy: 'type'
# commitGroupsSort: 'title'
# commitsSort: 'header'
# linkCompare: true
# linkReferences: true
# parserOpts:
# # detect JIRA issues in merge commits
# issuePrefixes: ['DEV-']
# mergePattern: "^Merge branch '(.*)' into (.*)$"
# mergeCorrespondence: ['branch_src', 'branch_dst']
presetConfig:
types: # looks like it only works with 'conventionalcommits' preset
- type: 'build'
section: '🧰 Build'
hidden: false
- type: 'chore'
section: '🐝 Chore'
hidden: false
- type: 'ci'
section: '🦊 CI/CD'
hidden: false
- type: 'docs'
section: '📔 Docs'
hidden: false
- type: 'example'
section: '📝 Examples'
hidden: false
- type: 'feat'
section: '🚀 Features'
hidden: false
- type: 'fix'
section: '🛠️ Fixes'
hidden: false
- type: 'perf'
section: '⏩ Performance'
- type: 'refactor'
section: '✂️ Refactor'
hidden: false
- type: 'revert'
section: '🙅‍♂️ Reverts'
- type: 'style'
section: '💈 Style'
- type: 'test'
section: '🧪 Tests'
hidden: false

prepare:

publish:
#TODO: Can't figure out how to turn off the default, unversioned source code from also being added as assets.
- path: "@semantic-release/github"
assets:
- path: "/tmp/dist/*.tar.gz"
label: "Versioned source code (tar.gz)"
- path: "/tmp/dist/*.zip"
label: "Versioned source code (zip)"

addChannel:
- path: '@semantic-release/github'

success:
- path: '@semantic-release/github'

fail:
- path: '@semantic-release/github'
Loading

0 comments on commit 0af475e

Please sign in to comment.