main: support generate declarative workflows #520
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: Go Continuous Integration | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
jobs: | |
golangci-lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version-file: 'go.mod' | |
- name: Run Go linters | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
args: --verbose | |
skip-pkg-cache: true | |
unit-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version-file: 'go.mod' | |
- name: Run tests | |
run: go test -race ./... | |
integration-test: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.USER_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version-file: 'go.mod' | |
- name: Install GitHub cli | |
run: | | |
sudo apt update | |
sudo apt install gh -y | |
- name: Validate pull request is not created yet | |
run: | | |
PULL_REQUESTS=$(gh pr list -R ${{ secrets.TEST_REPO }} --search "'add atlas ci workflow' in:title" --json headRefName | jq length) | |
if [ $PULL_REQUESTS -ne 0 ]; then | |
echo "Pull request already created" | |
exit 1 | |
fi | |
- name: Build extension | |
run: | | |
go build | |
- name: Install extension | |
run: | | |
gh extension install . | |
- name: Run GitHub atlas extension | |
run: | | |
gh atlas init-action -R ${{ secrets.TEST_REPO }} --token=${{ secrets.TEST_ATLAS_TOKEN }} --dir-name="sync-action-integration-test" --driver="sqlite" "sqlite_dir" \ | |
--config-path="atlas.hcl" --config-env="local" --flow=migrate | |
- name: Run GitHub atlas extension with invalid dir | |
id: invalid_dir | |
continue-on-error: true | |
run: | | |
gh atlas init-action -R ${{ secrets.TEST_REPO }} --token=${{ secrets.TEST_ATLAS_TOKEN }} --dir-name="invalid" --driver="sqlite" "sqlite_dir" \ | |
--config-path="atlas.hcl" --config-env="local" --flow=migrate | |
- name: Check invalid dir error | |
if : steps.invalid_dir.outcome == 'success' | |
run: | | |
echo "Invalid dir should fail" | |
exit 1 | |
- name: Validate pull request is created | |
uses: nick-fields/retry@v2 | |
with: | |
timeout_seconds: 20 | |
retry_wait_seconds: 5 | |
max_attempts: 4 | |
command: PULL_REQUESTS=$(gh pr list -R ${{ secrets.TEST_REPO }} --search "'add atlas ci workflow' in:title" --json headRefName | jq length) && [ $PULL_REQUESTS -eq 1 ] | |
- name: Cleanup the created pr, branch and secret | |
if: always() | |
run: | | |
BRANCH=$(gh pr list -R ${{ secrets.TEST_REPO }} --search "'add atlas ci workflow' in:title" --json headRefName | jq -r '.[0].headRefName') | |
gh pr close -R ${{ secrets.TEST_REPO }} $BRANCH -d | |
BRANCH_SUFFIX=${BRANCH: -6} | |
SECRET_NAME="ATLAS_CLOUD_TOKEN_$BRANCH_SUFFIX" | |
gh secret delete -R ${{ secrets.TEST_REPO }} $SECRET_NAME |