tests #1423
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: tests | |
| on: | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 3 * * *' | |
| jobs: | |
| test: | |
| strategy: | |
| matrix: | |
| go-version: ['1.23.x'] | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| fail-fast: false | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Install Go | |
| uses: actions/setup-go@v2 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Install Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 'latest' | |
| # Disable the wrapper: on Windows it creates a `terraform` file with | |
| # no extension that is not discoverable via PATHEXT, so go test falls | |
| # back to hc-install and trips the expired GPG check. | |
| terraform_wrapper: false | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Test | |
| run: go test ./... | |
| e2e_test: | |
| strategy: | |
| matrix: | |
| terraform-version: ["0.14", "1.0", "1.8", "latest"] | |
| config: [examples/basic, examples/advanced, examples/catalog, examples/ips, examples/on_call_calendars] | |
| fail-fast: false | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Install Go | |
| uses: actions/setup-go@v2 | |
| with: | |
| go-version: '1.23.x' | |
| - name: Install Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: ${{ matrix.terraform-version }} | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Add resources via Terraform | |
| run: make terraform CONFIGURATION="${{ matrix.config }}" ARGS="apply --auto-approve --input=false" | |
| env: | |
| BETTERUPTIME_API_TOKEN: ${{ secrets.UPTIME_E2E_TEAM_TOKEN }} | |
| - name: Plan resources via Terraform - must be empty | |
| run: | | |
| make terraform CONFIGURATION="${{ matrix.config }}" ARGS="plan --input=false --out=tfplan" | |
| make terraform CONFIGURATION="${{ matrix.config }}" ARGS="show --json tfplan > tfplan.json" | |
| CHANGES="$(jq "[.resource_changes[]? | select(.change.actions != [\"no-op\"])] | length" "${{ matrix.config }}/tfplan.json")" | |
| if [ "$CHANGES" == "0" ]; then | |
| echo "No planned changes detected after first apply. Success!" | |
| else | |
| echo "$CHANGES planned changes detected after first apply. Failure!" | |
| exit 1 | |
| fi | |
| env: | |
| BETTERUPTIME_API_TOKEN: ${{ secrets.UPTIME_E2E_TEAM_TOKEN }} | |
| - name: Destroy resources via Terraform | |
| if: always() | |
| run: make terraform CONFIGURATION="${{ matrix.config }}" ARGS="destroy --auto-approve --input=false" | |
| env: | |
| BETTERUPTIME_API_TOKEN: ${{ secrets.UPTIME_E2E_TEAM_TOKEN }} | |
| notify-linear: | |
| if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.event_name == 'schedule') }} | |
| needs: [e2e_test] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| actions: read | |
| steps: | |
| - name: "Gather failure context" | |
| id: ctx | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| FAILED=$(gh api \ | |
| "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}/jobs" \ | |
| --paginate \ | |
| --jq '[.jobs[] | |
| | select(.conclusion == "failure") | |
| | "- **\(.name)** — failed at _\([.steps[] | select(.conclusion == "failure") | .name] | join(", "))_"] | |
| | join("\n")') | |
| if [ -z "$FAILED" ]; then | |
| FAILED="_(no failed jobs reported by the API yet)_" | |
| fi | |
| { | |
| echo "failed_jobs<<CTXEOF" | |
| echo "$FAILED" | |
| echo "CTXEOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: "Create Linear issue" | |
| env: | |
| LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }} | |
| LINEAR_TEAM_ID: ${{ secrets.LINEAR_TEAM_ID }} | |
| LINEAR_STATUS_ID: ${{ secrets.LINEAR_STATUS_PLAN_ID }} | |
| LINEAR_PROJECT_ID: ${{ secrets.LINEAR_PROJECT_ID }} | |
| LINEAR_ASSIGNEE_ID: ${{ secrets.LINEAR_ASSIGNEE_ID }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| RUN_ATTEMPT: ${{ github.run_attempt }} | |
| EVENT_NAME: ${{ github.event_name }} | |
| SHA: ${{ github.sha }} | |
| COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | |
| FAILED_JOBS: ${{ steps.ctx.outputs.failed_jobs }} | |
| run: | | |
| SHORT_SHA="${SHA:0:7}" | |
| # head_commit is only populated on push events; skip the line otherwise | |
| COMMIT_LINE="**Commit:** \`$SHORT_SHA\`" | |
| if [ -n "$COMMIT_MESSAGE" ]; then | |
| COMMIT_SUBJECT="$(printf '%s' "$COMMIT_MESSAGE" | head -n1)" | |
| COMMIT_LINE="**Commit:** \`$SHORT_SHA\` — $COMMIT_SUBJECT" | |
| fi | |
| ATTEMPT_NOTE="" | |
| if [ "$RUN_ATTEMPT" != "1" ]; then | |
| ATTEMPT_NOTE=" (attempt #$RUN_ATTEMPT)" | |
| fi | |
| TITLE="E2E failure: ${{ github.workflow }} (${{ github.repository }})" | |
| DESCRIPTION=$(cat <<EOF | |
| **${{ github.workflow }}** failed on \`${{ github.ref_name }}\` in \`${{ github.repository }}\` via \`$EVENT_NAME\`$ATTEMPT_NOTE | |
| **Failing jobs:** | |
| $FAILED_JOBS | |
| $COMMIT_LINE | |
| [View failing run]($RUN_URL) | |
| EOF | |
| ) | |
| PAYLOAD=$(jq -n \ | |
| --arg query 'mutation IssueCreate($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { identifier url } } }' \ | |
| --arg title "$TITLE" \ | |
| --arg description "$DESCRIPTION" \ | |
| --arg teamId "$LINEAR_TEAM_ID" \ | |
| --arg assigneeId "$LINEAR_ASSIGNEE_ID" \ | |
| --arg stateId "$LINEAR_STATUS_ID" \ | |
| --arg projectId "$LINEAR_PROJECT_ID" \ | |
| '{ | |
| query: $query, | |
| variables: { | |
| input: { | |
| title: $title, | |
| description: $description, | |
| teamId: $teamId, | |
| assigneeId: $assigneeId, | |
| stateId: $stateId, | |
| projectId: $projectId, | |
| priority: 2 | |
| } | |
| } | |
| }') | |
| curl -sSf -X POST https://api.linear.app/graphql \ | |
| -H "Authorization: $LINEAR_API_KEY" \ | |
| -H 'Content-Type: application/json' \ | |
| -d "$PAYLOAD" |