internal: handle empty API URL from env (#292) #272
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
}' |