github.com/purpleclay/gitz@v0.8.2-0.20240515052600-43f80eea2fe1/testdata/tagsigningkey.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	git "github.com/purpleclay/gitz"
     8  )
     9  
    10  var (
    11  	gpgPublicKeyID = os.Getenv("GPG_PUBLIC_KEY_ID")
    12  	gpgFingerprint = os.Getenv("GPG_FINGERPRINT")
    13  )
    14  
    15  func main() {
    16  	gitc, _ := git.NewClient()
    17  
    18  	if _, err := gitc.Tag("0.1.0",
    19  		git.WithSigningKey(gpgPublicKeyID),
    20  		git.WithAnnotation("withsigningkey")); err != nil {
    21  		log.Fatal(err.Error())
    22  	}
    23  
    24  	verif, err := gitc.VerifyTag("0.1.0")
    25  	if err != nil {
    26  		log.Fatal(err.Error())
    27  	}
    28  
    29  	if verif.Tagger.Name != "batman" {
    30  		log.Fatalf("invalid tagger name, expecting: 'batman' but received: '%s'", verif.Tagger.Name)
    31  	}
    32  
    33  	if verif.Tagger.Email != "batman@dc.com" {
    34  		log.Fatalf("invalid tagger email, expecting: 'batman@dc.com' but received: '%s'", verif.Tagger.Email)
    35  	}
    36  
    37  	if verif.Annotation != "withsigningkey" {
    38  		log.Fatalf("invalid annotation, expecting: 'withsigningkey' but received: '%s'", verif.Annotation)
    39  	}
    40  
    41  	if verif.Signature.Fingerprint != gpgFingerprint {
    42  		log.Fatalf("invalid fingerprint, expecting: '%s' but received: '%s'", gpgFingerprint, verif.Signature.Fingerprint)
    43  	}
    44  
    45  	if verif.Signature.Author.Name != "batman" {
    46  		log.Fatalf("invalid signed-by name, expecting: 'batman' but received: '%s'", verif.Signature.Author.Name)
    47  	}
    48  
    49  	if verif.Signature.Author.Email != "batman@dc.com" {
    50  		log.Fatalf("invalid signed-by email, expecting: 'batman@dc.com' but received: '%s'", verif.Signature.Author.Email)
    51  	}
    52  }