Skip to content

Commit

Permalink
[minor] add CI to lint/test/release (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Mar 21, 2024
1 parent 5ccb81b commit c94db2c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Create release
on:
pull_request_target:
branches:
- main
types:
- closed
permissions:
contents: write
actions: write
jobs:
release:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: install autotag binary
run: curl -sL https://git.io/autotag-install | sudo sh -s -- -b /usr/bin
- name: create release
run: |-
TAG=$(autotag)
git tag $TAG
git push origin $TAG
gh release create $TAG
gh workflow run goreleaser.yml --ref $TAG
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

21 changes: 21 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: lint-test
on: [push]
permissions:
contents: read

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
- name: Install dependencies
run: go get .
- name: Build
run: go build -v ./...
- name: Test with the Go CLI
run: go test -v ./...
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters:
enable:
- gofmt

12 changes: 9 additions & 3 deletions cmd/arxiv.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Thank you to arXiv for use of its open access interoperability.`,
wr := csv.NewWriter(os.Stdout)

// CSV header
wr.Write([]string{
err = wr.Write([]string{
"id",
"field_edtf_date_issued",
"title",
Expand All @@ -92,6 +92,9 @@ Thank you to arXiv for use of its open access interoperability.`,
"file",
"arXiv search query",
})
if err != nil {
log.Fatalf("Unable to write to CSV: %v", err)
}
categoryNames := arxiv.GetCategoryLabels()
for _, query := range queries {

Expand Down Expand Up @@ -121,7 +124,7 @@ Thank you to arXiv for use of its open access interoperability.`,
pattern := `/abs/([0-9a-z\-]+(\/|\.)\d+)(?:v\d+)?$`
re := regexp.MustCompile(pattern)

for true {
for {
for _, e := range result.Entries {

log.Println("Pausing between requests. arXiv requests a three second delay between API requests...")
Expand Down Expand Up @@ -176,7 +179,7 @@ Thank you to arXiv for use of its open access interoperability.`,
doi := fmt.Sprintf(`{"attr0":"doi","value":"%s"}`, e.DOI)
identifiers = append(identifiers, doi)
}
wr.Write([]string{
err = wr.Write([]string{
e.ID,
strings.Split(e.Published.String(), " ")[0],
utils.TrimToMaxLen(e.Title, 255),
Expand All @@ -190,6 +193,9 @@ Thank you to arXiv for use of its open access interoperability.`,
e.PDF,
query,
})
if err != nil {
log.Fatalf("Unable to write to CSV: %v", err)
}
wr.Flush()

if e.PDF != "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"unicode/utf8"
Expand All @@ -18,7 +18,7 @@ func FetchEmails(url string) ([]string, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return queries, err
Expand Down

0 comments on commit c94db2c

Please sign in to comment.