From 883714b491eaad407f6cea5a7e18914bbb4baac0 Mon Sep 17 00:00:00 2001 From: moelsayed Date: Tue, 25 Feb 2025 15:26:19 +0100 Subject: [PATCH 1/2] Add release github action --- .github/workflows/release.yaml | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..39084ee --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,66 @@ +name: release + +on: + push: + branches: + - main + +jobs: + version_check: + name: Release version + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Read and validate VERSION + id: version + run: | + VERSION=$(cat VERSION) + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version format in VERSION file: $VERSION" + exit 1 + fi + echo "New version: $VERSION" + echo "version=$VERSION" >> $GITHUB_ENV + + - name: Check if VERSION is already tagged + id: check_tag + run: | + if git rev-parse "refs/tags/${{ env.version }}" >/dev/null 2>&1; then + echo "Tag ${{ env.version }} already exists. Skipping release." + exit 0 + fi + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Prepare the release + run: | + make prepare-release + git diff --exit-code + + - name: Create Git tag + run: | + AUTHOR_NAME=$(git log -1 --pretty=format:'%an') + AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae') + echo "Tagging as $AUTHOR_NAME <$AUTHOR_EMAIL>" + + git config user.name "$AUTHOR_NAME" + git config user.email "$AUTHOR_EMAIL" + + git tag -a "${{ env.version }}" -m "Release ${{ env.version }}" + git push origin "${{ env.version }}" + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.version }} + name: Release ${{ env.version }} + body: "Automated release for version ${{ env.version }}" + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From efe7ef6731484bb74c154dd7252572cc7df2b20c Mon Sep 17 00:00:00 2001 From: moelsayed Date: Wed, 26 Feb 2025 11:34:19 +0100 Subject: [PATCH 2/2] add -dev versions support --- .github/workflows/release.yaml | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 39084ee..c08e4d0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: release +name: Versioned Release on: push: @@ -17,13 +17,19 @@ jobs: id: version run: | VERSION=$(cat VERSION) - if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then echo "Invalid version format in VERSION file: $VERSION" exit 1 fi echo "New version: $VERSION" echo "version=$VERSION" >> $GITHUB_ENV + - name: Skip release if version is a dev version + if: contains(env.version, '-dev') + run: | + echo "Skipping development version release: ${{ env.version }}" + exit 0 + - name: Check if VERSION is already tagged id: check_tag run: | @@ -32,22 +38,15 @@ jobs: exit 0 fi - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Prepare the release - run: | - make prepare-release - git diff --exit-code - - name: Create Git tag run: | AUTHOR_NAME=$(git log -1 --pretty=format:'%an') AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae') echo "Tagging as $AUTHOR_NAME <$AUTHOR_EMAIL>" + echo "AUTHOR_NAME=$AUTHOR_NAME" >> $GITHUB_ENV + echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_ENV + git config user.name "$AUTHOR_NAME" git config user.email "$AUTHOR_EMAIL" @@ -64,3 +63,12 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Push dev VERSION + run: | + echo "${{ env.version }}-dev" > VERSION + git config user.name "${{ env.AUTHOR_NAME }}" + git config user.email "${{ env.AUTHOR_EMAIL }}" + git add VERSION + git commit -m "Update VERSION to ${{ env.version }}-dev" + git push origin main