Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,53 @@ jobs:
- name: Check for recent commits
id: check
run: |
git fetch --tags

LATEST_TAG=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"

# Prevent double release on the same day (unless manual dispatch)
if [ "${{ github.event_name }}" != "workflow_dispatch" ] && [ "$LATEST_TAG" != "v0.0.0" ]; then
TAG_DATE=$(git log -1 --format=%as "$LATEST_TAG")
TODAY=$(date +%Y-%m-%d)
echo "Tag Date: $TAG_DATE, Today: $TODAY"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: will we encounter this case? i assume if the daily intersects with the less frequent releases?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is to prevent double release when Sunday lines up with first of the month.


if [ "$TAG_DATE" = "$TODAY" ]; then
echo "Already released $LATEST_TAG today. Skipping."
echo "count=0" >> $GITHUB_OUTPUT
exit 0
fi
fi

if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "count=1" >> $GITHUB_OUTPUT
else
COUNT=$(git log --since="1 week ago" --oneline | wc -l)
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COUNT=$(git log --oneline | wc -l)
else
COUNT=$(git log "$LATEST_TAG"..HEAD --oneline | wc -l)
fi
echo "count=$COUNT" >> $GITHUB_OUTPUT
fi

- name: Determine Version Bump
if: steps.check.outputs.count > 0
id: bump_logic
run: |
if [ "${{ github.event.inputs.release_tag }}" = "" ]; then
LATEST_TAG=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "v1.0.0")
BASE_VERSION=${LATEST_TAG#v}

IFS='.' read -r major minor patch <<< "$BASE_VERSION"

if [ "${{ github.event.inputs.release_tag }}" != "" ]; then
NEW_TAG="${{ github.event.inputs.release_tag }}"
else
BUMP="patch"
if [ "$(date +%d)" = "01" ]; then BUMP="minor"; fi
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
BUMP="${{ github.event.inputs.version_type }}"
fi

LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0")
# Strip the 'v' prefix
BASE_VERSION=${LATEST_TAG#v}

IFS='.' read -r major minor patch <<< "$BASE_VERSION"

if [ "$BUMP" = "major" ]; then
major=$((major + 1)); minor=0; patch=0
elif [ "$BUMP" = "minor" ]; then
Expand All @@ -76,8 +99,6 @@ jobs:
fi

NEW_TAG="v$major.$minor.$patch"
else
NEW_TAG="${{ github.event.inputs.release_tag }}"
fi
echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "Using version: $NEW_TAG"
Expand All @@ -90,16 +111,6 @@ jobs:
version: ${{ steps.bump_logic.outputs.tag }}
tag: ${{ steps.bump_logic.outputs.tag }}

- name: Create GitHub Release

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why do we no longer need to do this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more confused as to why it was necessary in the first place. Isn't it being released in the later code anyways? To be honest, I don't really understand the way CI works here

https://github.com/UBC-Thunderbots/Software/pull/3595/changes#diff-87db21a973eed4fef5f32b267aa60fcee5cbdf03c67fafdc2a9b553bb0b15f34L136-L148

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the problem I encountered was that if you try and create a release directly, it won't allow you to append multiple files to the output. You have to create a draft release and attach all the files to it, then release it. Not sure if your fix will run into this issue, but that's why it was there in the first place.

if: steps.check.outputs.count > 0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.bump_logic.outputs.tag }}" \
--title "${{ steps.bump_logic.outputs.tag }}" \
--generate-notes \
--draft

upload_assets:
needs: prepare_release
if: needs.prepare_release.outputs.should_release == 'true'
Expand Down Expand Up @@ -128,10 +139,13 @@ jobs:
run: |
cd src
TAG="${{ needs.prepare_release.outputs.tag }}"

bazel build --show_timestamps --copt=-O3 --verbose_failures \
-- //software:unix_full_system_tar_gen
mv bazel-bin/software/unix_full_system_tar_gen.tar.gz "${{ runner.temp }}/unix_full_system_${{ needs.prepare_release.outputs.tag }}_${{ matrix.platform }}.tar.gz"
gh release upload "$TAG" "${{ runner.temp }}/unix_full_system_${{ needs.prepare_release.outputs.tag }}_${{ matrix.platform }}.tar.gz"

ARTIFACT_NAME="unix_full_system_${TAG}_${{ matrix.platform }}.tar.gz"
mv bazel-bin/software/unix_full_system_tar_gen.tar.gz "${{ runner.temp }}/$ARTIFACT_NAME"
gh release upload "$TAG" "${{ runner.temp }}/$ARTIFACT_NAME"

publish_release:
needs: [prepare_release, upload_assets]
Expand Down