|
| 1 | +name: Deploy tags |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + create-tag: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Read version file |
| 21 | + id: get-version |
| 22 | + run: | |
| 23 | + if [ -f "version" ]; then |
| 24 | + VERSION=$(cat version | tr -d '\n' | tr -d '\r') |
| 25 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 26 | + echo "Found version: $VERSION" |
| 27 | + else |
| 28 | + echo "Version file not found. Workflow cannot continue." |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + |
| 32 | + - name: Configure Git |
| 33 | + run: | |
| 34 | + git config user.name "GitHub Actions" |
| 35 | + git config user.email "github-actions@github.com" |
| 36 | + |
| 37 | + - name: Create or update tag |
| 38 | + run: | |
| 39 | + VERSION=${{ steps.get-version.outputs.VERSION }} |
| 40 | + |
| 41 | + # Check if tag exists in remote repository |
| 42 | + if git ls-remote --tags origin | grep -q "refs/tags/$VERSION$"; then |
| 43 | + echo "Tag $VERSION already exists, updating it..." |
| 44 | + |
| 45 | + # Delete the existing tag locally and remotely |
| 46 | + git tag -d "$VERSION" 2>/dev/null || true |
| 47 | + git push --delete origin "refs/tags/$VERSION" || echo "Failed to delete remote tag (it may not exist yet)" |
| 48 | + |
| 49 | + echo "Creating updated tag $VERSION pointing to current commit..." |
| 50 | + else |
| 51 | + echo "Creating new tag $VERSION..." |
| 52 | + fi |
| 53 | + |
| 54 | + # Create annotated tag on current commit |
| 55 | + git tag -a "$VERSION" -m "Version $VERSION" |
| 56 | + |
| 57 | + # Push the tag to remote |
| 58 | + git push origin "$VERSION" |
| 59 | + |
| 60 | + echo "✅ Tag $VERSION successfully created/updated!" |
0 commit comments