ci, versioning, lint improvements #22
This file contains hidden or 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: OpenVSwitch Provider CI/CD | ||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ master ] | ||
| workflow_dispatch: | ||
| inputs: | ||
| versionNumber: | ||
| description: 'Release version number (v#.#.#)' | ||
| type: string | ||
| required: false | ||
| # Limit concurrent runs to conserve resources and avoid conflicts | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| CI_COMMIT_AUTHOR: trvon | ||
| CI_COMMIT_EMAIL: [email protected] | ||
| GO_VERSION: '1.22' | ||
| jobs: | ||
| lint: | ||
| name: Lint | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| cache: true | ||
| - name: Run golangci-lint | ||
| uses: golangci/golangci-lint-action@v6 | ||
| with: | ||
| version: latest | ||
| args: --timeout=5m | ||
| - name: Run go vet | ||
| run: go vet ./... | ||
| - name: Check formatting | ||
| run: | | ||
| if [ -n "$(gofmt -s -l .)" ]; then | ||
| echo "Go code is not formatted:" | ||
| gofmt -s -d . | ||
| exit 1 | ||
| fi | ||
| security: | ||
| name: Security Checks | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| cache: true | ||
| - name: Run govulncheck | ||
| run: | | ||
| go install golang.org/x/vuln/cmd/govulncheck@latest | ||
| govulncheck ./... | ||
| - name: Run tests with race detector | ||
| run: go test -race -short ./... | ||
| unit-tests: | ||
| name: Unit Tests | ||
| needs: [lint] | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| cache: true | ||
| - name: Unit Tests | ||
| run: | | ||
| go test ./... -v -timeout=120s -coverprofile=coverage.out | ||
| timeout-minutes: 5 | ||
| - name: Upload coverage | ||
| uses: codecov/codecov-action@v4 | ||
| if: always() | ||
| with: | ||
| files: ./coverage.out | ||
| flags: unittests | ||
| fail_ci_if_error: false | ||
| acceptance-tests: | ||
| name: Acceptance Tests | ||
| needs: [lint] | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| container: | ||
| image: gns3/openvswitch:latest | ||
| volumes: | ||
| - /lib/modules:/lib/modules | ||
| options: --cap-add=NET_ADMIN --privileged | ||
| steps: | ||
| - name: Install dependencies | ||
| run: | | ||
| apk update | ||
| apk add --no-cache git make curl sudo iproute2 go | ||
| timeout-minutes: 5 | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Verify and setup Go | ||
| run: | | ||
| echo "Go binary location: $(which go)" | ||
| go version | ||
| echo "GOPATH: $GOPATH" | ||
| # Make sure Go binaries are in PATH | ||
| echo "PATH=$PATH:/usr/local/go/bin:$(go env GOPATH)/bin" >> $GITHUB_ENV | ||
| - name: Start Open vSwitch service | ||
| run: | | ||
| /usr/share/openvswitch/scripts/ovs-ctl start | ||
| ovs-vsctl show | ||
| timeout-minutes: 2 | ||
| - name: Run Acceptance Tests | ||
| env: | ||
| TF_ACC: 1 | ||
| run: | | ||
| go test ./openvswitch -v -timeout=300s | ||
| timeout-minutes: 10 | ||
| integration-tests: | ||
| name: Integration Tests | ||
| needs: [unit-tests, acceptance-tests, security] | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| matrix: | ||
| terraform_version: ['1.6.0', '1.10.5'] | ||
| opentofu_version: ['1.6.0', '1.8.10'] | ||
| container: | ||
| image: gns3/openvswitch:latest | ||
| volumes: | ||
| - /lib/modules:/lib/modules | ||
| options: --cap-add=NET_ADMIN --privileged | ||
| steps: | ||
| - name: Install dependencies | ||
| run: | | ||
| apk update | ||
| apk add --no-cache git make curl sudo iproute2 wget unzip go | ||
| timeout-minutes: 5 | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Verify and setup Go | ||
| run: | | ||
| echo "Go binary location: $(which go)" | ||
| go version | ||
| echo "GOPATH: $GOPATH" | ||
| # Make sure Go binaries are in PATH | ||
| echo "PATH=$PATH:/usr/local/go/bin:$(go env GOPATH)/bin" >> $GITHUB_ENV | ||
| - name: Build provider | ||
| run: | | ||
| go version | ||
| mkdir -p bin/ | ||
| go build -buildvcs=false -o bin/terraform-provider-openvswitch | ||
| # Make sure the provider binary is executable | ||
| chmod +x bin/terraform-provider-openvswitch | ||
| timeout-minutes: 5 | ||
| - name: Install Terraform | ||
| run: | | ||
| wget https://releases.hashicorp.com/terraform/${{ matrix.terraform_version }}/terraform_${{ matrix.terraform_version }}_linux_amd64.zip | ||
| unzip terraform_${{ matrix.terraform_version }}_linux_amd64.zip | ||
| mv terraform /usr/local/bin/ | ||
| terraform version | ||
| timeout-minutes: 5 | ||
| - name: Start Open vSwitch service | ||
| run: | | ||
| /usr/share/openvswitch/scripts/ovs-ctl start | ||
| ovs-vsctl show | ||
| timeout-minutes: 2 | ||
| - name: Test with example configuration | ||
| run: | | ||
| cd examples/sample-bridge | ||
| # Use dev override configuration | ||
| export TF_CLI_CONFIG_FILE="$(pwd)/terraform.tfrc" | ||
| # Skip init with dev overrides since the provider isn't published | ||
| terraform validate | ||
| terraform plan | ||
| timeout-minutes: 5 | ||
| - name: Install OpenTofu | ||
| run: | | ||
| wget https://github.com/opentofu/opentofu/releases/download/v${{ matrix.opentofu_version }}/tofu_${{ matrix.opentofu_version }}_linux_amd64.zip | ||
| unzip -o tofu_${{ matrix.opentofu_version }}_linux_amd64.zip | ||
| mv tofu /usr/local/bin/ | ||
| tofu version | ||
| timeout-minutes: 5 | ||
| - name: Test with OpenTofu | ||
| run: | | ||
| cd examples/opentofu-sample | ||
| # Use dev override configuration - works for OpenTofu too | ||
| export TF_CLI_CONFIG_FILE="$(pwd)/terraform.tfrc" | ||
| # Skip init with dev overrides since the provider isn't published | ||
| tofu validate | ||
| tofu plan | ||
| timeout-minutes: 5 | ||
| release: | ||
| name: Release | ||
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.versionNumber != '' | ||
| needs: [integration-tests] | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 45 | ||
| permissions: | ||
| contents: write | ||
| env: | ||
| VERSION: ${{ github.event.inputs.versionNumber }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| # Avoid persisting GITHUB_TOKEN credentials | ||
| persist-credentials: false | ||
| - name: Set version variables | ||
| id: version | ||
| run: | | ||
| echo "MAJOR_VERSION=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT | ||
| echo "CHANGELOG_VERSION=$(echo $VERSION | cut -c 2-)" >> $GITHUB_OUTPUT | ||
| timeout-minutes: 1 | ||
| - name: Generate changelog | ||
| run: | | ||
| echo "Generating changelog for version ${{ steps.version.outputs.CHANGELOG_VERSION }}" | ||
| # TODO: Implement changelog generation logic | ||
| mkdir -p .changes | ||
| echo "# ${{ steps.version.outputs.CHANGELOG_VERSION }}" > .changes/${{ steps.version.outputs.CHANGELOG_VERSION }}.md | ||
| echo "" >> .changes/${{ steps.version.outputs.CHANGELOG_VERSION }}.md | ||
| echo "## Changes" >> .changes/${{ steps.version.outputs.CHANGELOG_VERSION }}.md | ||
| echo "* Release version ${{ github.event.inputs.versionNumber }}" >> .changes/${{ steps.version.outputs.CHANGELOG_VERSION }}.md | ||
| timeout-minutes: 5 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| cache: true | ||
| - name: 'Terraform Provider Release' | ||
| uses: hashicorp/ghaction-terraform-provider-release/.github/workflows/community.yml@v4 | ||
| with: | ||
| gpg-private-key: '${{ secrets.GPG_PRIVATE_KEY }}' | ||
| setup-go-version-file: 'go.mod' | ||
| - name: Generate Release Notes | ||
| run: | | ||
| cd .changes | ||
| sed -e "1{/# /d;}" -e "2{/^$/d;}" ${{ steps.version.outputs.CHANGELOG_VERSION }}.md > /tmp/release-notes.txt | ||
| timeout-minutes: 2 | ||
| - name: GH Release | ||
| run: | | ||
| gh release create "${{ github.event.inputs.versionNumber }}" --notes-file /tmp/release-notes.txt --title "${{ github.event.inputs.versionNumber }}" | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| timeout-minutes: 5 | ||