Merge pull request #6 from klustrefs/fix/atty-security #9
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
| # Build and push the Klustre CSI container image to GHCR. | |
| name: Build and Push Image | |
| permissions: | |
| contents: read | |
| packages: write | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - release-* | |
| tags: | |
| - v* | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| inputs: | |
| image_tag: | |
| description: "SemVer tag for the pushed image (example: v0.0.1). Defaults to v0.0.1 when omitted." | |
| required: false | |
| default: v0.0.1 | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: klustrefs/klustre-csi-plugin | |
| DEFAULT_IMAGE_TAG: v0.0.1 | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Determine image tag | |
| id: vars | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| elif [ -n "${{ github.event.inputs.image_tag }}" ]; then | |
| VERSION="${{ github.event.inputs.image_tag }}" | |
| else | |
| VERSION="${DEFAULT_IMAGE_TAG}" | |
| fi | |
| if ! echo "${VERSION}" | grep -Eq '^v?[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then | |
| echo "Provided version '${VERSION}' is not a valid semver (allowing optional leading 'v')." >&2 | |
| exit 1 | |
| fi | |
| # Normalise to strip leading 'v' when tagging the image. | |
| CLEAN_VERSION="${VERSION#v}" | |
| echo "IMAGE_TAG=${CLEAN_VERSION}" >> "${GITHUB_ENV}" | |
| echo "Resolved image tag: ${CLEAN_VERSION}" | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
| labels: | | |
| org.opencontainers.image.source=${{ github.repository }} | |
| org.opencontainers.image.version=${{ env.IMAGE_TAG }} | |
| - name: Summary | |
| run: | | |
| echo "Published ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}" |