diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d10a600..9277411 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,196 +4,101 @@ on: push: branches: - '**' - workflow_dispatch: - inputs: - create-pr: - description: 'Create PR for auto-fixes' - required: false - default: 'false' - jobs: - check: - name: Check - runs-on: ubuntu-latest - strategy: - matrix: - go-version: ['1.21', '1.22'] - steps: - - uses: actions/checkout@v4 + jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go-version }} - - - name: Cache Go modules - uses: actions/cache@v3 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Check - run: make check - - - name: Lint - uses: golangci/golangci-lint-action@v4 - with: - version: v1.54 - skip-pkg-cache: true - - - name: Test - run: make test - - auto-fix: - name: Auto-fix code formatting and dependencies - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - - name: Cache Go modules - uses: actions/cache@v3 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Run auto-fix (format and tidy) - run: | - make fmt || true - go mod tidy - gofmt -s -w . - - - name: Check for changes - id: verify-changed-files - run: | - if git diff --quiet; then - echo "changed=false" >> $GITHUB_OUTPUT - else - echo "changed=true" >> $GITHUB_OUTPUT - fi - - - name: Create Pull Request for auto-fixes - if: steps.verify-changed-files.outputs.changed == 'true' - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GH_TOKEN }} - commit-message: 'chore: auto-fix code formatting and dependencies' - title: '[AUTO] Code formatting and dependency updates' - body: | - ## Automated Code Fixes - - This PR contains automatic fixes: - - Code formatting (gofmt) - - Import organization - - Go module cleanup (go mod tidy) - - Please review and merge if the changes look good. - branch: auto-fix/formatting-${{ github.run_number }} - delete-branch: true - labels: 'automated,auto-fix' - - start-runner: - name: Start self-hosted EC2 runner - needs: check - runs-on: ubuntu-latest - outputs: - label: ${{ steps.start-ec2-runner.outputs.label }} - ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - - - name: Start EC2 runner - id: start-ec2-runner - uses: namecheap/ec2-github-runner@feat/al2023-support - with: - mode: start - github-token: ${{ secrets.GH_TOKEN }} - ec2-image-owner: 699717368611 - ec2-image-filters: > - [ - { "Name": "name", "Values": ["nc-al2023-ami-hvm-x86_64-master-*"] } - ] - ec2-instance-type: t3.small - subnet-id: subnet-01c4ff5a - security-group-id: sg-106ec76d - eip-allocation-id: eipalloc-1796f61b - iam-role-name: AmazonSSMRoleForInstancesQuickSetup - aws-resource-tags: > - [ - { "Key": "Name", "Value": "github_runner" }, - { "Key": "GitHubRepository", "Value": "${{ github.repository }}" } - ] - - acceptance_test: - name: Acceptance test - runs-on: ${{ needs.start-runner.outputs.label }} - needs: start-runner - concurrency: acceptance_test - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - run: | - curl https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz -o go1.21.5.linux-amd64.tar.gz - rm -rf .go-instance - mkdir .go-instance - tar -C .go-instance -xzf go1.21.5.linux-amd64.tar.gz - echo "#!/bin/bash" >> go-env.sh - echo "" >> go-env.sh - echo "export PATH=$PATH:$(pwd)/.go-instance/go/bin" >> go-env.sh - echo "export HOME=$(pwd)" >> go-env.sh - chmod +x go-env.sh - source go-env.sh - go version - go env GOPATH - - - name: Acceptance Test - run: | - export CGO_ENABLED=0 - source go-env.sh - make testacc - env: - NAMECHEAP_USER_NAME: saTerraformProvider - NAMECHEAP_API_USER: saTerraformProvider - NAMECHEAP_TEST_DOMAIN: terraform-provider-test.net - NAMECHEAP_USE_SANDBOX: true - NAMECHEAP_API_KEY: ${{ secrets.NAMECHEAP_API_KEY }} - - stop-runner: - name: Stop self-hosted EC2 runner - needs: - - start-runner - - acceptance_test - runs-on: ubuntu-latest - if: ${{ always() }} - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - - - name: Stop EC2 runner - uses: namecheap/ec2-github-runner@main - with: - mode: stop - github-token: ${{ secrets.GH_TOKEN }} - label: ${{ needs.start-runner.outputs.label }} - ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }} + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Check + run: make check + + - name: Lint + uses: golangci/golangci-lint-action@v4 + with: + version: v1.54 + skip-pkg-cache: true + + - name: Test + run: make test + + start-runner: + name: Start self-hosted EC2 runner + needs: check + runs-on: ubuntu-latest + outputs: + label: ${{ steps.start-ec2-runner.outputs.label }} + ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Start EC2 runner + id: start-ec2-runner + uses: namecheap/ec2-github-runner@feat/al2023-support + with: + mode: start + github-token: ${{ secrets.GH_TOKEN }} + ec2-image-owner: 699717368611 + ec2-image-filters: > + [ + { "Name": "name", "Values": ["nc-al2023-ami-hvm-x86_64-master-*"] } + ] + ec2-instance-type: t3.small + subnet-id: subnet-01c4ff5a + security-group-id: sg-106ec76d + eip-allocation-id: eipalloc-1796f61b + iam-role-name: AmazonSSMRoleForInstancesQuickSetup + aws-resource-tags: > + [ + { "Key": "Name", "Value": "github_runner" }, + { "Key": "GitHubRepository", "Value": "${{ github.repository }}" } + ] + + acceptance_test: + name: Acceptance test + runs-on: ${{ needs.start-runner.outputs.label }} + needs: start-runner + concurrency: acceptance_test + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + run: | + curl https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz -o go1.21.5.linux-amd64.tar.gz + rm -rf .go-instance + mkdir .go-instance + tar -C .go-instance -xzf go1.21.5.linux-amd64.tar.gz + echo "#!/bin/bash" >> go-env.sh + echo "" >> go-env.sh + echo "export PATH=$PATH:$(pwd)/.go-instance/go/bin" >> go-env.sh + echo "export HOME=$(pwd)" >> go-env.sh + chmod +x go-env.sh + source go-env.sh + go version + go env GOPATH + + - name: Acceptance Test + run: | + export CGO_ENABLED=0 + source go-env.sh + make testacc + env: + NAMECHEAP_USER_NAME: saTerraformProvider + NAMECHEAP_API_USER: saTerraformProvider + NAMECHEAP_TEST_DOMAIN: terraform-provider-test.net + NAMECHEAP_USE_SANDBOX: true + NAMECHEAP_API_KEY: ${{ secrets.NAMECHEAP_API_KEY }} + +