Skip to content

Commit

Permalink
feat: sync directory to public tenant (#14)
Browse files Browse the repository at this point in the history
* feat: sync directory to public tenant

Signed-off-by: Giau. Tran Minh <[email protected]>

* fix: change CI to public tenant

Signed-off-by: Giau. Tran Minh <[email protected]>

* fix: fixed CI permission

Signed-off-by: Giau. Tran Minh <[email protected]>

---------

Signed-off-by: Giau. Tran Minh <[email protected]>
  • Loading branch information
giautm authored Apr 25, 2023
1 parent 0ce6699 commit 6760f27
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
run: go test -race ./...
integration-tests:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
Expand All @@ -59,8 +62,8 @@ jobs:
with:
dir: internal/testdata/basic/migrations
driver: mysql
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
cloud-url: ${{ secrets.ATLAS_CLOUD_URL }}
cloud-public: true
cloud-url: https://gh-api.atlasgo.link
docker:
runs-on: ubuntu-latest
needs: [golangci-lint, unit-tests, integration-tests]
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
cloud-token:
description: 'Token for using Atlas Cloud (should be passed as a secret).'
required: true
cloud-public:
description: 'Set true to send report to gh.atlasgo.cloud'
default: false
required: false
driver:
description: 'Driver for the target database: mysql, postgres, sqlite'
required: true
Expand Down
22 changes: 15 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import (
)

const (
cloudDomain = "https://api.atlasgo.cloud"
cloudDomain = "https://api.atlasgo.cloud"
cloudDomainPublic = "https://gh-api.atlasgo.cloud"
)

func main() {
act := githubactions.New()
token := act.GetInput("cloud-token")
if token == "" {
act.Fatalf("cloud-token is required")
}
c := client(act)
input, err := Input(act)
if err != nil {
act.Fatalf("failed to parse input: %v", err)
Expand All @@ -32,7 +30,6 @@ func main() {
act.Fatalf("failed to archive migration dir: %v", err)
}
input.Dir = arc
c := client(act)
if err := c.ReportDir(context.Background(), input); err != nil {
act.Fatalf("failed to upload dir: %v", err)
}
Expand Down Expand Up @@ -95,13 +92,24 @@ func driver(s string) (atlascloud.Driver, error) {
}

func client(act *githubactions.Action) *atlascloud.Client {
isPublic := strings.ToLower(act.GetInput("cloud-public")) == "true"
token := act.GetInput("cloud-token")
if token == "" && isPublic {
var err error
token, err = act.GetIDToken(context.Background(), "ariga://atlas-sync-action")
if err != nil {
act.Fatalf("failed to get id token: %v", err)
}
}
if token == "" {
act.Fatalf("cloud-token is required")
}
d := cloudDomain
if u := act.GetInput("cloud-url"); u != "" {
switch u := act.GetInput("cloud-url"); {
case u != "":
d = u
case isPublic:
d = cloudDomainPublic
}
u, err := url.Parse(d)
if err != nil {
Expand Down

0 comments on commit 6760f27

Please sign in to comment.