|
| 1 | +name: Build |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + tags: |
| 7 | + - "v*.*.*" |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + workflow_dispatch: |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + packages: write |
| 15 | + pull-requests: read |
| 16 | +jobs: |
| 17 | + commitlint: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + env: |
| 20 | + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 # fetch-depth is required |
| 25 | + |
| 26 | + - uses: wagoid/commitlint-github-action@v6 |
| 27 | + |
| 28 | + test: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 # Required for pre-commit to be able scan history |
| 34 | + |
| 35 | + - name: Set up Go |
| 36 | + uses: actions/setup-go@v5 |
| 37 | + with: |
| 38 | + go-version-file: go.mod |
| 39 | + |
| 40 | + - uses: actions/setup-python@v5 |
| 41 | + with: |
| 42 | + python-version: 3.x |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: go install ./... |
| 46 | + |
| 47 | + - name: go-vet |
| 48 | + run: go vet -v ./... |
| 49 | + |
| 50 | + - name: go-test |
| 51 | + run: go test -v ./... |
| 52 | + |
| 53 | + - name: golangci-lint |
| 54 | + uses: golangci/golangci-lint-action@v6 |
| 55 | + |
| 56 | + - uses: pre-commit/action@v3.0.1 |
| 57 | + |
| 58 | + e2e: |
| 59 | + runs-on: ubuntu-latest |
| 60 | + env: |
| 61 | + HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} |
| 62 | + DISK_IMAGE: docker-ce |
| 63 | + DISK_SIZE: "30" |
| 64 | + MACHINE_ID: test-${{ github.run_id }} |
| 65 | + MACHINE_FOLDER: ${{ github.workspace }}./ssh |
| 66 | + MACHINE_TYPE: "cx22" |
| 67 | + REGION: "nbg1" |
| 68 | + SSH_KEY_PUB: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK2sB1n570BgGJ3+I0Dgzxhlf9ukc+Hp+C/zsIH4J8Xm vscode@df47ba471beb" |
| 69 | + SSH_KEY: ${{ secrets.SSH_KEY }} |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - uses: hetznercloud/setup-hcloud@v1 |
| 74 | + |
| 75 | + - name: Set up SSH keys |
| 76 | + run: | |
| 77 | + mkdir -p ${MACHINE_FOLDER} |
| 78 | + echo ${SSH_KEY_PUB} > ${MACHINE_FOLDER}/sshkey.pub |
| 79 | + echo ${SSH_KEY} > ${MACHINE_FOLDER}/sshkey |
| 80 | + ls -la ${MACHINE_FOLDER} |
| 81 | +
|
| 82 | + - name: Set up Go |
| 83 | + uses: actions/setup-go@v5 |
| 84 | + with: |
| 85 | + go-version-file: go.mod |
| 86 | + |
| 87 | + - run: go build -o provider . |
| 88 | + |
| 89 | + - name: Create command |
| 90 | + run: ./provider create |
| 91 | + |
| 92 | + - name: Run command |
| 93 | + env: |
| 94 | + COMMAND: hostname |
| 95 | + run: ./provider command | grep ${MACHINE_ID} |
| 96 | + |
| 97 | + - name: Stop command |
| 98 | + run: ./provider stop |
| 99 | + |
| 100 | + - name: Start command |
| 101 | + run: ./provider start |
| 102 | + |
| 103 | + - name: Run command |
| 104 | + env: |
| 105 | + COMMAND: hostname |
| 106 | + run: ./provider command | grep ${MACHINE_ID} |
| 107 | + |
| 108 | + - name: Delete command |
| 109 | + run: ./provider delete |
| 110 | + |
| 111 | + # This can fail due to resources failing to detach properly |
| 112 | + - name: Ensure destruction |
| 113 | + if: ${{ always() }} |
| 114 | + uses: nick-fields/retry@v3 |
| 115 | + with: |
| 116 | + timeout_minutes: 10 |
| 117 | + max_attempts: 3 |
| 118 | + command: ./hack/hcloud_destroy.sh |
| 119 | + |
| 120 | + build: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + outputs: |
| 123 | + is_tag: ${{ steps.branch-name.outputs.is_tag }} |
| 124 | + env: |
| 125 | + # Used to get default HCloud values |
| 126 | + HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} |
| 127 | + steps: |
| 128 | + - uses: actions/checkout@v4 |
| 129 | + with: |
| 130 | + fetch-depth: 0 |
| 131 | + |
| 132 | + - name: Set up Go |
| 133 | + uses: actions/setup-go@v5 |
| 134 | + with: |
| 135 | + go-version-file: go.mod |
| 136 | + |
| 137 | + - run: go version |
| 138 | + |
| 139 | + - name: Get branch names |
| 140 | + id: branch-name |
| 141 | + uses: tj-actions/branch-names@v8 |
| 142 | + with: |
| 143 | + strip_tag_prefix: v |
| 144 | + |
| 145 | + - name: Generate version info |
| 146 | + id: version |
| 147 | + run: | |
| 148 | + if [ "${{ steps.branch-name.outputs.is_tag }}" = "true" ]; |
| 149 | + then |
| 150 | + echo "version=${{ steps.branch-name.outputs.tag }}" >> "$GITHUB_OUTPUT" |
| 151 | + else |
| 152 | + echo "version=development" >> "$GITHUB_OUTPUT" |
| 153 | + fi |
| 154 | +
|
| 155 | + echo "commit_id=${GITHUB_SHA}" >> "$GITHUB_OUTPUT" |
| 156 | + echo "gitRepo=github.com/${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT" |
| 157 | +
|
| 158 | + - name: Compile binaries |
| 159 | + run: ./hack/build.sh |
| 160 | + env: |
| 161 | + GIT_COMMIT: ${{ steps.version.outputs.commit_id }} |
| 162 | + GIT_REPO: ${{ steps.version.outputs.gitRepo }} |
| 163 | + RELEASE_VERSION: ${{ steps.version.outputs.version }} |
| 164 | + |
| 165 | + - uses: actions/upload-artifact@v4 |
| 166 | + with: |
| 167 | + name: dist |
| 168 | + path: dist/ |
| 169 | + |
| 170 | + publish: |
| 171 | + runs-on: ubuntu-latest |
| 172 | + needs: |
| 173 | + - build |
| 174 | + - commitlint |
| 175 | + - e2e |
| 176 | + - test |
| 177 | + if: needs.build.outputs.is_tag == 'true' |
| 178 | + steps: |
| 179 | + - uses: actions/download-artifact@v4 |
| 180 | + with: |
| 181 | + name: dist |
| 182 | + path: dist/ |
| 183 | + |
| 184 | + - uses: actions/setup-node@v4 |
| 185 | + |
| 186 | + - name: Build Changelog |
| 187 | + id: github_release |
| 188 | + uses: mikepenz/release-changelog-builder-action@v3 |
| 189 | + env: |
| 190 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 191 | + |
| 192 | + - name: Release |
| 193 | + uses: softprops/action-gh-release@v1 |
| 194 | + with: |
| 195 | + body: ${{ steps.github_release.outputs.changelog }} |
| 196 | + files: dist/* |
0 commit comments