Skip to content

Commit

Permalink
Update release.yml again.
Browse files Browse the repository at this point in the history
  • Loading branch information
ActoryOu committed Nov 4, 2024
1 parent 5563bca commit 0549ae3
Showing 1 changed file with 98 additions and 57 deletions.
155 changes: 98 additions & 57 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ env:
repository_zip_name: ${{ github.event.repository.name }}-${{ github.event.inputs.version_number }}.zip
# Source folder list for version number updates
source_folder_list: "source test"
repository_name: ${{ github.event.repository.name }}
version_number: ${{ github.event.inputs.version_number }}
actor: ${{ github.actor }}
commit_id: ${{ github.event.inputs.commit_id }}

jobs:
clean-existing-tag-and-release:
if: ${{ github.event.inputs.delete_existing_tag_release == 'true' }}
runs-on: ubuntu-latest
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
Expand All @@ -37,10 +34,10 @@ jobs:
- name: Check if tag exists
run: |
git fetch origin
if git tag --list ${{ env.version_number }}
if git tag --list $VERSION_NUMBER
then
echo "Deleting existing tag for ${{ env.version_number }}"
git push origin --delete tags/${{ env.version_number }}
echo "Deleting existing tag for $VERSION_NUMBER"
git push origin --delete tags/$VERSION_NUMBER
fi
- name: Check if release exists
Expand All @@ -49,10 +46,10 @@ jobs:
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt-get install gh
if gh release list | grep ${{ env.version_number }}
if gh release list | grep $VERSION_NUMBER
then
echo "Deleting existing release for ${{ env.version_number }}
gh release delete --yes ${{ env.version_number }}
echo "Deleting existing release for $VERSION_NUMBER"
gh release delete --yes $VERSION_NUMBER
fi
add-sbom-and-tag-commit:
Expand All @@ -64,47 +61,61 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.commit_id }}
ref: ${{ github.event.inputs.commit_id }}

- name: Configure git identity
env:
ACTOR: ${{ github.actor }}
run: |
git config --global user.name ${{ env.actor }}
git config --global user.email ${{ env.actor }}@users.noreply.github.com
git config --global user.name "$ACTOR"
git config --global user.email "$ACTOR"@users.noreply.github.com
- name: create a new branch that references commit id
run: git checkout -b ${{ env.version_number }} ${{ env.commit_id }}
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
COMMIT_ID: ${{ github.event.inputs.version_number }}
run: git checkout -b "$VERSION_NUMBER" "$COMMIT_ID"

- name: Update version number in source files
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
echo "${{ env.source_folder_list }}" | \
xargs -n 1 sh -c \
'find $1 -type f \( -name "*.c" -o -name "*.h" \) \
-exec sed -i -b -E "0,/^ \* ${{ env.repository_name }}/s/^ \* ${{ env.repository_name }}.*/ \* ${{ env.repository_name }} ${{ env.version_number }}/g" {} +'
-exec sed -i -b -E "0,/^ \* $REPO_NAME/s/^ \* $REPO_NAME.*/ \* $REPO_NAME $VERSION_NUMBER/g" {} +'
git add .
git commit -m '[AUTO][RELEASE]: Update version number in source files'
git push -u origin ${{ env.version_number }}
git push -u origin "$VERSION_NUMBER"
- name : Update version number in manifest.yml
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
run: |
sed -i -b '0,/^version/s/^version.*/version: "${{ env.version_number }}"/g' ./manifest.yml
sed -i -b '0,/^version/s/^version.*/version: "$VERSION_NUMBER"/g' ./manifest.yml
git add .
git commit -m '[AUTO][RELEASE]: Update version number in manifest.yml'
git push -u origin ${{ env.version_number }}
git push -u origin "$VERSION_NUMBER"
- name : Update version number in doxygen
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
run: |
sed -i -b 's/PROJECT_NUMBER *=.*/PROJECT_NUMBER = ${{ env.version_number }}/g' ./docs/doxygen/config.doxyfile
sed -i -b 's/PROJECT_NUMBER *=.*/PROJECT_NUMBER = $VERSION_NUMBER/g' ./docs/doxygen/config.doxyfile
git add .
git commit -m '[AUTO][RELEASE]: Update version number in doxygen'
git push -u origin ${{ env.version_number }}
git push -u origin "$VERSION_NUMBER"
- name : Update MQTT version number macro
if: ${{ env.repository_name == 'coreMQTT' }}
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
if: ${{ github.event.repository.name == 'coreMQTT' }}
run: |
sed -i -b 's/^\#define MQTT_LIBRARY_VERSION .*/\#define MQTT_LIBRARY_VERSION "${{ env.version_number }}"/g' source/include/core_mqtt.h
sed -i -b 's/^\#define MQTT_LIBRARY_VERSION .*/\#define MQTT_LIBRARY_VERSION "$VERSION_NUMBER"/g' source/include/core_mqtt.h
git add .
git commit -m '[AUTO][RELEASE]: Update version number macro in source/include/core_mqtt.h'
git push -u origin ${{ env.version_number }}
git push -u origin "$VERSION_NUMBER"
- name: Generate SBOM
uses: FreeRTOS/CI-CD-Github-Actions/sbom-generator@main
Expand All @@ -113,22 +124,30 @@ jobs:
source_path: ./source

- name: commit SBOM file
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
run: |
git add .
git commit -m 'Update SBOM'
git push -u origin ${{ env.version_number }}
git push -u origin "$VERSION_NUMBER"
- name: Tag Commit and Push to remote
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
git tag ${{ env.version_number }} -a -m "${{ env.repository_name }} Library ${{ env.version_number }}"
git tag "$VERSION_NUMBER" -a -m "$REPO_NAME Library $VERSION_NUMBER"
git push origin --tags
- name: Verify tag on remote
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
COMMIT_ID: ${{ github.event.inputs.commit_id }}
run: |
git tag -d ${{ env.version_number }}
git tag -d "$VERSION_NUMBER"
git remote update
git checkout tags/${{ env.version_number }}
git diff ${{ env.commit_id }} tags/${{ env.version_number }}
git checkout tags/"$VERSION_NUMBER"
git diff "$COMMIT_ID" tags/"$VERSION_NUMBER"
create-zip:
if: ${{ ( github.event.inputs.delete_existing_tag_release == 'true' && success() ) || ( github.event.inputs.delete_existing_tag_release == 'false' && always() ) }}
Expand All @@ -142,87 +161,107 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.version_number }}
path: ${{ env.repository_name }}
ref: ${{ github.event.inputs.version_number }}
path: ${{ github.event.repository.name }}
submodules: recursive

- name: Checkout disabled submodules
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd ${{ env.repository_name }}
cd "$REPO_NAME"
git submodule update --init --checkout --recursive
- name: Create ZIP
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
zip -r ${{ env.repository_zip_name }} ${{ env.repository_name }} -x "*.git*"
zip -r ${{ env.repository_zip_name }} "$REPO_NAME" -x "*.git*"
ls ./
- name: Validate created ZIP
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
mkdir zip-check
mv ${{ env.repository_zip_name }} zip-check
cd zip-check
unzip ${{ env.repository_zip_name }} -d ${{ env.repository_compressed_name }}
ls ${{ env.repository_compressed_name }}
diff -r -x "*.git*" ${{ env.repository_compressed_name }}/${{ env.repository_name }}/ ../${{ env.repository_name }}/
diff -r -x "*.git*" ${{ env.repository_compressed_name }}/"$REPO_NAME"/ ../"$REPO_NAME"/
cd ../
- name: Check version number in source files
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd zip-check/${{ env.repository_compressed_name }}/${{ env.repository_name }}
cd zip-check/${{ env.repository_compressed_name }}/"$REPO_NAME"
# List all the *.h *.c files in <source_folder_list>
SOURCE_FILE_LIST=$( echo "${{ env.source_folder_list }}" | \
xargs -n 1 sh -c 'find $1 -type f \( -name "*.c" -o -name "*.h" \)' )
# List all the files which contain " * <repository_name>.*" in SOURCE_FILE_LIST
SOURCE_FILE_WITH_VERSION_LIST=$( grep -l " \* ${{ env.repository_name }}.*" $SOURCE_FILE_LIST )
SOURCE_FILE_WITH_VERSION_LIST=$( grep -l " \* $REPO_NAME.*" $SOURCE_FILE_LIST )
# Compare the <version_number> with input version number in files in SOURCE_FILE_LIST
echo $SOURCE_FILE_WITH_VERSION_LIST | xargs -I{} sh -c \
'grep -x " \* ${{ env.repository_name }} ${{ env.version_number }}" {} && \
echo {} : match ${{ env.repository_name }} ${{ env.version_number }} || \
{ echo "{} : ${{ env.repository_name }} ${{ env.version_number }} not found"; exit 255; }'
'grep -x " \* $REPO_NAME $VERSION_NUMBER" {} && \
echo {} : match "$REPO_NAME" "$VERSION_NUMBER" || \
{ echo "{} : $REPO_NAME $VERSION_NUMBER not found"; exit 255; }'
- name: Check version number in doxygen
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd zip-check/${{ env.repository_compressed_name }}/${{ env.repository_name }}
cd zip-check/${{ env.repository_compressed_name }}/"$REPO_NAME"
# find "PROJECT_NUMBER = <version_number>"
DOXYGEN_VERSION_NUMBER=$(grep -x "[ ]*PROJECT_NUMBER[ ]*=[ ]*[^ ]*[ ]*" docs/doxygen/config.doxyfile | awk -F= '{gsub(" ","",$2); print $2 }');
# compare the <version_number> with input version number
[[ $DOXYGEN_VERSION_NUMBER == "${{ env.version_number }}" ]] \
&& echo "config.doxyfile : match ${{ env.version_number }}" \
|| { echo "config.doxyfile : $DOXYGEN_VERSION_NUMBER doesn't match ${{ env.version_number }}"; exit 255; }
[[ $DOXYGEN_VERSION_NUMBER == "$VERSION_NUMBER" ]] \
&& echo "config.doxyfile : match $VERSION_NUMBER" \
|| { echo "config.doxyfile : $DOXYGEN_VERSION_NUMBER doesn't match $VERSION_NUMBER"; exit 255; }
- name: Check version number in manifest.yml
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd zip-check/${{ env.repository_compressed_name }}/${{ env.repository_name }}
cd zip-check/${{ env.repository_compressed_name }}/"$REPO_NAME"
# find the first occurence of "version: <version_number>" and comare the <version_number> with input version number
MANIFEST_VESION_NUMBER=$( grep -m 1 -E "^version:[ ]*\".*\"[ ]*" manifest.yml | awk -F: '{ gsub(" ","",$2); gsub("\"","",$2); print $2 }' );
# compare the <version_number> with input version number
[[ $MANIFEST_VESION_NUMBER == "${{ env.version_number }}" ]] \
&& echo "manifest.yml : match ${{ env.version_number }}" \
|| { echo "manifest.yml : $MANIFEST_VESION_NUMBER doesn't match ${{ env.version_number }}"; exit 255; }
[[ $MANIFEST_VESION_NUMBER == "$VERSION_NUMBER" ]] \
&& echo "manifest.yml : match $VERSION_NUMBER" \
|| { echo "manifest.yml : $MANIFEST_VESION_NUMBER doesn't match $VERSION_NUMBER"; exit 255; }
- name: Check MQTT version number macro in header file
if: ${{ env.repository_name == 'coreMQTT' }}
env:
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
REPO_NAME: ${{ github.event.repository.name }}
if: ${{ github.event.repository.name == 'coreMQTT' }}
run: |
cd zip-check/${{ env.repository_compressed_name }}/${{ env.repository_name }}
cd zip-check/${{ env.repository_compressed_name }}/"$REPO_NAME"
# find "#define MQTT_LIBRARY_VERSION <version_number>" in core_mqtt.h
MACRO_VERSION_NUMBER=$(grep -x "^\#define[ ]*MQTT_LIBRARY_VERSION[ ]*\".*\"[ ]*" source/include/core_mqtt.h | awk '{gsub("\"","",$3); print $3 }');
# compare the <version_number> with input version number
[[ $MACRO_VERSION_NUMBER == "${{ env.version_number }}" ]] \
&& echo "core_mqtt.h : match ${{ env.version_number }}" \
|| { echo "core_mqtt.h : $MACRO_VERSION_NUMBER doesn't match ${{ env.version_number }}"; exit 255; }
[[ $MACRO_VERSION_NUMBER == "$VERSION_NUMBER" ]] \
&& echo "core_mqtt.h : match $VERSION_NUMBER" \
|| { echo "core_mqtt.h : $MACRO_VERSION_NUMBER doesn't match $VERSION_NUMBER"; exit 255; }
- name: Build
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd zip-check/${{ env.repository_compressed_name }}/${{ env.repository_name }}
cd zip-check/${{ env.repository_compressed_name }}/"$REPO_NAME"
sudo apt-get install -y lcov
cmake -S test -B build/ \
-G "Unix Makefiles" \
Expand All @@ -232,8 +271,10 @@ jobs:
make -C build/ all
- name: Test
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd zip-check/${{ env.repository_compressed_name }}/${{ env.repository_name }}/build/
cd zip-check/${{ env.repository_compressed_name }}/"$REPO_NAME"/build/
ctest -E system --output-on-failure
cd ..
Expand All @@ -252,7 +293,7 @@ jobs:
- name: Doxygen generation
uses: FreeRTOS/CI-CD-Github-Actions/doxygen-generation@main
with:
ref: ${{ env.version_number }}
ref: ${{ github.event.inputs.version_number }}
add_release: "true"

create-release:
Expand All @@ -269,9 +310,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.version_number }}
release_name: ${{ env.version_number }}
body: Release ${{ env.version_number }} of the ${{ env.repository_name }} Library.
tag_name: ${{ github.event.inputs.version_number }}
release_name: ${{ github.event.inputs.version_number }}
body: Release ${{ github.event.inputs.version_number }} of the ${{ github.event.repository.name }} Library.
draft: false
prerelease: false

Expand Down

0 comments on commit 0549ae3

Please sign in to comment.