diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..ac75ad5 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,85 @@ +name: Auto Release on Release Branch + +on: + pull_request: + types: [ closed ] + branches: [ release ] + +permissions: + contents: write + +jobs: + auto-release: + # Only run if PR was merged to release branch (not just closed) + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract tags from PR labels + id: get_tags_labels + run: | + # Get PR labels and extract version + LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}' + echo "PR Labels: $LABELS" + + # Look for version label (e.g., "v1.0.0", "version:1.0.0", etc.) + VERSION=$(echo $LABELS | jq -r '.[] | select(test("^(v|version:)?[0-9]+\\.[0-9]+\\.[0-9]+")) | gsub("^(v|version:)"; "")') + + # Look for zeam network tags (devnet0, devnet1, testnet, mainnet) + ZEAM_TAG=$(echo $LABELS | jq -r '.[] | select(test("^(devnet[0-9]+|testnet[0-9]*|mainnet)$"))') + + if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then + echo "ℹ️ No version label found" + else + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "git_tag=v$VERSION" >> $GITHUB_OUTPUT + echo "✅ Version found: $VERSION" + fi + + if [ -n "$ZEAM_TAG" ] && [ "$ZEAM_TAG" != "null" ]; then + echo "zeam_tag=$ZEAM_TAG" >> $GITHUB_OUTPUT + echo "has_network_tag=true" >> $GITHUB_OUTPUT + echo "✅ Found network tag: $ZEAM_TAG" + else + echo "has_network_tag=false" >> $GITHUB_OUTPUT + echo "ℹ️ No network tag found (optional)" + fi + + # Require at least one label (version or network) + if { [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; } && { [ -z "$ZEAM_TAG" ] || [ "$ZEAM_TAG" = "null" ]; }; then + echo "❌ No usable label found! Please add a version (e.g. v1.0.0) or network tag (e.g. devnet0, testnet, mainnet)" + exit 1 + fi + + - name: Create and push git tags + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Create version tag if version label exists + if [ -n "${{ steps.get_tags_labels.outputs.version }}" ] && [ "${{ steps.get_tags_labels.outputs.version }}" != "null" ]; then + if git rev-parse "${{ steps.get_tags_labels.outputs.git_tag }}" >/dev/null 2>&1; then + echo "⚠️ Tag ${{ steps.get_tags_labels.outputs.git_tag }} already exists, skipping" + else + git tag -a "${{ steps.get_tags_labels.outputs.git_tag }}" -m "Release version ${{ steps.get_tags_labels.outputs.version }}" + git push origin "${{ steps.get_tags_labels.outputs.git_tag }}" + echo "✅ Created version tag ${{ steps.get_tags_labels.outputs.git_tag }}" + fi + fi + + # Create zeam network tag if network label exists + if [ "${{ steps.get_tags_labels.outputs.has_network_tag }}" = "true" ]; then + ZEAM_GIT_TAG="${{ steps.get_tags_labels.outputs.zeam_tag }}" + if git rev-parse "$ZEAM_GIT_TAG" >/dev/null 2>&1; then + echo "⚠️ Zeam tag $ZEAM_GIT_TAG already exists, skipping" + else + git tag -a "$ZEAM_GIT_TAG" -m "Zeam network tag for ${{ steps.get_tags_labels.outputs.zeam_tag }}" + git push origin "$ZEAM_GIT_TAG" + echo "✅ Created zeam tag $ZEAM_GIT_TAG" + fi + fi