-
Notifications
You must be signed in to change notification settings - Fork 6
130 lines (130 loc) · 4.22 KB
/
cd.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Build and Upload to CDN
on:
workflow_dispatch:
inputs:
commit:
description: 'Commit SHA'
required: false
version:
description: 'Version (should follow semver v1.2.3)'
required: false
push:
branches:
- master
tags:
- 'v*'
jobs:
test:
uses: ./.github/workflows/ci-go.yaml
secrets: inherit
build:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
env:
REGISTRY: "docker.io"
IMAGE_NAME: "arigaio/atlas-action"
DOCKERHUB_USERNAME: arigaio
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ github.event.inputs.commit || 'master' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub (${{ env.REGISTRY }})
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=sha
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.RELEASE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.RELEASE_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Setup Go Environment
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Install Atlas
uses: ariga/setup-atlas@v0
- name: Set BINARY_NAME
id: set_binary_name
env:
VERSION: ${{ github.event.inputs.version || github.ref_name }}
run: |
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "BINARY_NAME=atlas-action-$VERSION" >> $GITHUB_ENV
- name: Compile Go Binary
run: |
COMMIT=$(git rev-parse --short HEAD)
go build -o atlas-action -ldflags "-s -w -X main.version=$VERSION -X main.commit=$COMMIT" ./cmd/atlas-action
OUTPUT=$(./atlas-action --version)
if [[ $(echo $OUTPUT | grep -i "^atlas-action version $VERSION-$COMMIT") ]]; then
echo "Version=$OUTPUT"
else
echo "unexpected output: $OUTPUT, expected: atlas-action version $VERSION-$COMMIT"
exit 1
fi
env:
CGO_ENABLED: 0
- name: Upload binary to S3
run: |
aws s3 cp ./atlas-action s3://release.ariga.io/atlas-action/$BINARY_NAME
env:
AWS_REGION: us-east-1
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
push: true
# Run end-to-end test on the published binary.
e2e-test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- name: Run Migrate Lint
env:
GITHUB_TOKEN: ${{ github.token }}
uses: jenseng/dynamic-uses@v1
with:
uses: ariga/atlas-action/migrate/lint@${{ github.event.inputs.version || 'v1' }}
with: '{
"dir": "file://atlasaction/testdata/migrations",
"dev-url": "sqlite://dev?mode=memory",
"dir-name": "test-dir-sqlite"
}'
- name: Run Migrate Push
uses: jenseng/dynamic-uses@v1
with:
uses: ariga/atlas-action/migrate/push@${{ github.event.inputs.version || 'v1' }}
with: '{
"dir": "file://atlasaction/testdata/migrations",
"dev-url": "sqlite://dev?mode=memory",
"dir-name": "test-dir-sqlite"
}'