From de57d5450a3f88ef73cc343356e8e7630b7bab46 Mon Sep 17 00:00:00 2001
From: Pierre Carrier <pc@rrier.fr>
Date: Mon, 13 Nov 2023 18:17:39 +0100
Subject: [PATCH] update github workflows

---
 .github/workflows/go-presubmit.yml | 10 +++++-----
 .github/workflows/goreleaser.yml   | 16 +++++++---------
 gauth.go                           | 10 +++++++++-
 gauth/gauth.go                     |  6 +++---
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/.github/workflows/go-presubmit.yml b/.github/workflows/go-presubmit.yml
index 983da59..6b734fa 100644
--- a/.github/workflows/go-presubmit.yml
+++ b/.github/workflows/go-presubmit.yml
@@ -13,13 +13,13 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        go-version: ['1.17', '1.18', '1.19']
+        go-version: ['1.19', '1.20', '1.21']
     steps:
     - name: Install Go ${{ matrix.go-version }}
-      uses: actions/setup-go@v3
+      uses: actions/setup-go@v4
       with:
         go-version: ${{ matrix.go-version }}
-    - uses: actions/checkout@v3
-    - uses: creachadair/go-presubmit-action@v1
+    - uses: actions/checkout@v4
+    - uses: creachadair/go-presubmit-action@v2
       with:
-        staticcheck-version: "2022.1.3"
+        staticcheck-version: "2023.1.6"
diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml
index 5965aa6..dfabad0 100644
--- a/.github/workflows/goreleaser.yml
+++ b/.github/workflows/goreleaser.yml
@@ -17,31 +17,29 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout
-        uses: actions/checkout@v2
-        with:
-          fetch-depth: 0
+        uses: actions/checkout@v4
 
       - name: Set up Go
-        uses: actions/setup-go@v2
+        uses: actions/setup-go@v4
         with:
-          go-version: 1.17
+          go-version: 1.21
 
       - name: Run GoReleaser release (SKIP publish)
-        uses: goreleaser/goreleaser-action@v3
+        uses: goreleaser/goreleaser-action@v5
         if: startsWith(github.ref, 'refs/tags/') != true
         with:
           distribution: goreleaser
           version: latest
-          args: release --rm-dist --skip-publish
+          args: release --clean --skip=publish --snapshot
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Run GoReleaser release
-        uses: goreleaser/goreleaser-action@v3
+        uses: goreleaser/goreleaser-action@v5
         if: startsWith(github.ref, 'refs/tags/')
         with:
           distribution: goreleaser
           version: latest
-          args: release --rm-dist
+          args: release --clean
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/gauth.go b/gauth.go
index 96a91f7..4b3595d 100644
--- a/gauth.go
+++ b/gauth.go
@@ -113,6 +113,10 @@ func addCode(accountName string) {
 	// Check for encryption and ask for password if necessary
 	_, isEncrypted, err := gauth.ReadConfigFile(cfgPath)
 
+	if err != nil {
+		log.Fatalf("Reading config: %v", err)
+	}
+
 	password, err := []byte(nil), nil
 
 	if isEncrypted {
@@ -169,13 +173,17 @@ func removeCode(accountName string) {
 	// Check for encryption and ask for password if necessary
 	_, isEncrypted, err := gauth.ReadConfigFile(cfgPath)
 
+	if err != nil {
+		log.Fatalf("Reading config: %v", err)
+	}
+
 	password, err := []byte(nil), nil
 
 	if isEncrypted {
 		password, err = getPassword()
 
 		if err != nil {
-			log.Fatalf("reading passphrase: %v", err)
+			log.Fatalf("Reading passphrase: %v", err)
 		}
 	}
 
diff --git a/gauth/gauth.go b/gauth/gauth.go
index 55c0897..b41d48e 100644
--- a/gauth/gauth.go
+++ b/gauth/gauth.go
@@ -12,7 +12,7 @@ import (
 	"errors"
 	"fmt"
 	"hash"
-	"io/ioutil"
+	"os"
 	"strings"
 	"time"
 
@@ -78,7 +78,7 @@ func CodesAtTimeStep(u *otpauth.URL, timeStep uint64) (prev, curr, next string,
 // ReadConfigFile reads the config file at path and returns its contents and
 // whether it is encrypted or not
 func ReadConfigFile(path string) ([]byte, bool, error) {
-	data, err := ioutil.ReadFile(path)
+	data, err := os.ReadFile(path)
 	if err != nil {
 		return nil, false, err
 	}
@@ -184,7 +184,7 @@ func WriteConfigFile(path string, passwd []byte, newConfig []byte) error {
 		newConfig = append(saltedPrefix, newConfig...)
 	}
 
-	err = ioutil.WriteFile(path, newConfig, 0)
+	err = os.WriteFile(path, newConfig, 0)
 
 	if err != nil {
 		return fmt.Errorf("writing config: %v", err)