ssh-proxy OSS alignment #46
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: Self-Tests | |
| # See https://github.com/k8shell-io/internals/tree/main/docs/handbook/docs/development/release_and_testing for information on release and testing processes. | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| paths: | |
| - "docker/**" | |
| - "internal/**" | |
| - "pkg/**" | |
| - "tests/**" | |
| - "go.mod" | |
| - "go.sum" | |
| - "Makefile" | |
| - ".github/workflows/self-tests.yaml" | |
| pull_request: | |
| branches: | |
| - "*" | |
| paths: | |
| - "docker/**" | |
| - "internal/**" | |
| - "pkg/**" | |
| - "tests/**" | |
| - "go.mod" | |
| - "go.sum" | |
| - "Makefile" | |
| - ".github/workflows/self-tests.yaml" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| checks: write | |
| pull-requests: write | |
| jobs: | |
| Self-Tests: | |
| runs-on: k8shell-runner | |
| if: github.event_name == 'push' || github.event.pull_request.draft == false | |
| env: | |
| GO111MODULE: on | |
| strategy: | |
| matrix: | |
| go-version: ["1.24.5"] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| # Fetch full history for version calculation (git describe) | |
| # Set to 1 if you don't need git history | |
| fetch-depth: 0 | |
| - name: Set up Git for private modules | |
| run: | | |
| git config --global url."https://${{ secrets.GH_PAT_TOKEN }}:x-oauth-basic@github.com/".insteadOf "https://github.com/" | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| cache: true | |
| # Compile ssh-proxy and kbox executables | |
| - name: Build binaries | |
| run: make build | |
| # Verify binaries execute successfully | |
| - name: Run binary smoke tests (test-self) | |
| run: make test-self | |
| - name: Upload test reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: self-test-reports-go${{ matrix.go-version }} | |
| path: reports/ | |
| retention-days: 30 | |
| - name: Publish test results | |
| if: always() | |
| uses: EnricoMi/publish-unit-test-result-action@v2 | |
| with: | |
| files: reports/**/*-junit.xml | |
| check_name: Self-Tests (Go ${{ matrix.go-version }}) | |
| # Calculate version and image tag based on PR or push context | |
| # PRs: pr-{number}-{short-sha} using actual PR head commit | |
| # Pushes: git describe output | |
| - name: Determine image tag and version | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| # For PRs: use actual PR head SHA, not merge commit | |
| COMMIT_ID=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7) | |
| PR_NUMBER=${{ github.event.pull_request.number }} | |
| IMAGE_TAG="pr-${PR_NUMBER}-${COMMIT_ID}" | |
| IMAGE_TAG_LATEST="pr-${PR_NUMBER}-latest" | |
| VERSION="pr-${PR_NUMBER}-${COMMIT_ID}" | |
| else | |
| # For pushes: use current commit and git describe | |
| COMMIT_ID=$(git rev-parse --short HEAD) | |
| VERSION=$(git describe --tags --match 'v*' | sed 's/-g.*//') | |
| IMAGE_TAG="$VERSION" | |
| IMAGE_TAG_LATEST="latest" | |
| fi | |
| echo "REPO_NAME=$(cat docker/ssh-proxy/BUILD)" >> $GITHUB_ENV | |
| echo "COMMIT_ID=$COMMIT_ID" >> $GITHUB_ENV | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
| echo "IMAGE_TAG_LATEST=$IMAGE_TAG_LATEST" >> $GITHUB_ENV | |
| # Vendor dependencies and copy source files to Docker build context | |
| - name: Prepare Docker build context | |
| run: make vendor | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| # Authenticate to Harbor registry | |
| - name: Login to Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: registry.k8shell.io | |
| username: ${{ secrets.HARBOR_USER }} | |
| password: ${{ secrets.HARBOR_PASSWORD }} | |
| # Build container image and push to registry with version metadata | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: docker/ssh-proxy/Dockerfile | |
| tags: | | |
| registry.k8shell.io/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | |
| registry.k8shell.io/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG_LATEST }} | |
| push: true | |
| build-args: | | |
| VERSION=${{ env.VERSION }} | |
| COMMIT_ID=${{ env.COMMIT_ID }} | |
| # Add build information to job summary for easy access | |
| - name: Add image info to job summary | |
| run: | | |
| echo "## 🐳 Docker Image Built" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Image:** \`registry.k8shell.io/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** \`${{ env.VERSION }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Commit:** \`${{ env.COMMIT_ID }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Pull command:" >> $GITHUB_STEP_SUMMARY | |
| echo '```bash' >> $GITHUB_STEP_SUMMARY | |
| echo "docker pull registry.k8shell.io/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY |