Publish Initial Publish #8
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: Publish | |
| run-name: Publish ${{ inputs.publish_type }} | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| publish_type: | |
| description: "Publish Options" | |
| default: "Initial Publish" | |
| type: choice | |
| options: | |
| - Initial Publish | |
| - Redeploy | |
| - Dry Run | |
| version: | |
| description: 'Version to publish (default: latest release)' | |
| required: true | |
| type: string | |
| default: latest | |
| jobs: | |
| setup: | |
| name: Setup | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| outputs: | |
| release_version: ${{ steps.version-output.outputs.version }} | |
| steps: | |
| - name: Version output | |
| id: version-output | |
| env: | |
| INPUT_VERSION: ${{ inputs.version }} | |
| run: | | |
| if [[ "$INPUT_VERSION" == "latest" || "$INPUT_VERSION" == "" ]]; then | |
| VERSION=$(curl -sSfL "https://api.github.com/repos/bitwarden/key-connector/releases" | jq -c '.[] | select(.tag_name) | .tag_name' | head -1 | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') | |
| if [[ -z "$VERSION" ]]; then | |
| echo "Failed to fetch latest version" | |
| exit 1 | |
| fi | |
| echo "Latest Released Version: $VERSION" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Release Version: $INPUT_VERSION" | |
| echo "version=$INPUT_VERSION" >> "$GITHUB_OUTPUT" | |
| fi | |
| publish-docker: | |
| name: Publish Docker images | |
| runs-on: ubuntu-24.04 | |
| needs: setup | |
| env: | |
| _RELEASE_VERSION: ${{ needs.setup.outputs.release_version }} | |
| permissions: | |
| id-token: write | |
| packages: write | |
| steps: | |
| - name: Install Cosign | |
| uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Pull versioned image | |
| run: docker pull "ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION" | |
| - name: Tag as latest | |
| run: docker tag "ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION" "ghcr.io/bitwarden/key-connector:latest" | |
| - name: Push latest image | |
| if: ${{ inputs.publish_type != 'Dry Run' }} | |
| run: docker push "ghcr.io/bitwarden/key-connector:latest" | |
| - name: Log out of Docker | |
| run: docker logout ghcr.io |