|
| 1 | +name: Build and publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 1 * * *" |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v5 |
| 15 | + |
| 16 | + - name: AWS CLI v2 |
| 17 | + uses: imehedi/actions-awscli-v2@latest |
| 18 | + continue-on-error: true |
| 19 | + with: |
| 20 | + args: s3 cp s3://${{ vars.SC_ARTIFACTS_BUCKET }}/bitwarden-cli-docker/REVISION . --endpoint-url ${{ vars.SC_AMS_AWS_ENDPOINT }} |
| 21 | + env: |
| 22 | + AWS_ACCESS_KEY_ID: ${{ secrets.SC_AWS_KEY_ID }} |
| 23 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.SC_AWS_SECRET_ACCESS_KEY }} |
| 24 | + AWS_DEFAULT_REGION: "nl-ams" |
| 25 | + |
| 26 | + - name: Tag |
| 27 | + id: tag |
| 28 | + env: |
| 29 | + GITHUB_TOKEN: ${{ github.token }} |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | + # Find latest stable Bitwarden CLI (cli-v*) using GitHub API (authenticated) |
| 33 | + REPO_TAG=$(curl -sS \ |
| 34 | + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ |
| 35 | + -H "Accept: application/vnd.github+json" \ |
| 36 | + "https://api.github.com/repos/bitwarden/clients/releases?per_page=100" \ |
| 37 | + | jq -r ' |
| 38 | + [ .[] |
| 39 | + | select(.tag_name | startswith("cli-v")) |
| 40 | + | select(.draft==false and .prerelease==false) |
| 41 | + | .tag_name ] |
| 42 | + | sort_by( sub("^cli-v"; "") | split(".") | map(tonumber) ) |
| 43 | + | last |
| 44 | + | sub("^cli-v"; "") |
| 45 | + ') |
| 46 | + if [ -z "${REPO_TAG:-}" ] || ! echo "$REPO_TAG" | grep -Eq '^[0-9]+(\.[0-9]+){2}$'; then |
| 47 | + echo "Failed to resolve latest Bitwarden CLI version" >&2 |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + echo "Latest Bitwarden CLI: $REPO_TAG" |
| 51 | + PREVIOUS_TAG=$(cat REVISION || echo "") |
| 52 | + mkdir -p temp/ |
| 53 | + if [ "$REPO_TAG" = "$PREVIOUS_TAG" ]; then |
| 54 | + echo "No new tags. Skipping." |
| 55 | + echo "skipped=true" >> $GITHUB_OUTPUT |
| 56 | + echo $REPO_TAG > temp/REVISION |
| 57 | + exit 0 |
| 58 | + fi |
| 59 | + VERSION="$REPO_TAG" |
| 60 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 61 | + echo $REPO_TAG > temp/REVISION |
| 62 | +
|
| 63 | + - name: AWS CLI v2 |
| 64 | + uses: imehedi/actions-awscli-v2@latest |
| 65 | + with: |
| 66 | + args: s3 cp temp/REVISION s3://${{ vars.SC_ARTIFACTS_BUCKET }}/bitwarden-cli-docker/REVISION --endpoint-url ${{ vars.SC_AMS_AWS_ENDPOINT }} |
| 67 | + env: |
| 68 | + AWS_ACCESS_KEY_ID: ${{ secrets.SC_AWS_KEY_ID }} |
| 69 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.SC_AWS_SECRET_ACCESS_KEY }} |
| 70 | + AWS_DEFAULT_REGION: "nl-ams" |
| 71 | + |
| 72 | + # Buildx explicit setup not required for single-arch; build-push-action |
| 73 | + # provisions a builder automatically. |
| 74 | + |
| 75 | + - name: Extract metadata (tags, labels) for Docker |
| 76 | + id: meta |
| 77 | + if: ${{ steps.tag.outputs.skipped != 'true' }} |
| 78 | + uses: docker/metadata-action@v5 |
| 79 | + with: |
| 80 | + images: ghcr.io/icoretech/bitwarden-cli-docker |
| 81 | + labels: | |
| 82 | + org.opencontainers.image.description=Bitwarden CLI |
| 83 | + org.opencontainers.image.source=https://github.com/icoretech/bitwarden-cli-docker |
| 84 | + org.opencontainers.image.title=bitwarden-cli |
| 85 | + org.opencontainers.image.vendor=iCoreTech, Inc. |
| 86 | + tags: | |
| 87 | + type=raw,value=${{ env.VERSION }} |
| 88 | +
|
| 89 | + - name: Login to GitHub Container Registry |
| 90 | + uses: docker/login-action@v3 |
| 91 | + if: ${{ steps.tag.outputs.skipped != 'true' }} |
| 92 | + with: |
| 93 | + registry: ghcr.io |
| 94 | + username: ${{ github.actor }} |
| 95 | + password: ${{ secrets.PACKAGES_PAT }} |
| 96 | + |
| 97 | + - name: Build and push Docker image |
| 98 | + uses: docker/build-push-action@v6 |
| 99 | + if: ${{ steps.tag.outputs.skipped != 'true' }} |
| 100 | + with: |
| 101 | + platforms: linux/amd64 |
| 102 | + push: ${{ github.event_name != 'pull_request' }} |
| 103 | + tags: ${{ steps.meta.outputs.tags }} |
| 104 | + labels: ${{ steps.meta.outputs.labels }} |
| 105 | + # No provenance attestation for simplicity and max compatibility |
| 106 | + build-args: BW_VERSION=${{ env.VERSION }} |
0 commit comments