Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 69 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

name: Release
permissions:
contents: write
attestations: write
id-token: write
contents: read

on:
pull_request:
Expand Down Expand Up @@ -39,6 +37,10 @@

build:
needs: plan
permissions:
contents: read
attestations: write
id-token: write
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -69,9 +71,9 @@
archive: zip
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
targets: ${{ matrix.target }}

Expand All @@ -80,39 +82,46 @@
run: cargo install cross --git https://github.com/cross-rs/cross --tag v0.2.5

- name: Build
env:
MATRIX_CROSS: ${{ matrix.cross }}
MATRIX_TARGET: ${{ matrix.target }}
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }} --locked
if [ "${MATRIX_CROSS}" = "true" ]; then
cross build --release --target "${MATRIX_TARGET}" --locked
else
cargo build --release --target ${{ matrix.target }} --locked
cargo build --release --target "${MATRIX_TARGET}" --locked
fi
shell: bash

- name: Package (unix)
if: matrix.archive == 'tar.gz'
env:
MATRIX_TARGET: ${{ matrix.target }}
run: |
ARTIFACT="google-workspace-cli-${{ matrix.target }}"
ARTIFACT="google-workspace-cli-${MATRIX_TARGET}"
mkdir -p staging
cp "target/${{ matrix.target }}/release/gws" staging/
cp "target/${MATRIX_TARGET}/release/gws" staging/
cp LICENSE README.md CHANGELOG.md staging/
tar czf "${ARTIFACT}.tar.gz" -C staging .
shasum -a 256 "${ARTIFACT}.tar.gz" > "${ARTIFACT}.tar.gz.sha256"
shell: bash

- name: Package (windows)
if: matrix.archive == 'zip'
env:
MATRIX_TARGET: ${{ matrix.target }}
run: |
$ARTIFACT = "google-workspace-cli-${{ matrix.target }}"
$ARTIFACT = "google-workspace-cli-$env:MATRIX_TARGET"
New-Item -ItemType Directory -Path $ARTIFACT
Copy-Item "target/${{ matrix.target }}/release/gws.exe" "$ARTIFACT/"
Copy-Item "target/$env:MATRIX_TARGET/release/gws.exe" "$ARTIFACT/"
Copy-Item LICENSE, README.md, CHANGELOG.md "$ARTIFACT/"
Compress-Archive -Path "$ARTIFACT/*" -DestinationPath "$ARTIFACT.zip"
(Get-FileHash "$ARTIFACT.zip" -Algorithm SHA256).Hash.ToLower() + " $ARTIFACT.zip" | Out-File -Encoding ascii "$ARTIFACT.zip.sha256"
shell: pwsh

- name: Attest
if: github.ref_type == 'tag'
uses: actions/attest-build-provenance@43d14bc2b83dec42d39ecae14e916627a18bb661 # v3
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3
with:
subject-path: google-workspace-cli-${{ matrix.target }}.${{ matrix.archive }}

Expand All @@ -127,8 +136,10 @@
needs: [plan, build]
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
Expand All @@ -139,9 +150,12 @@
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRERELEASE: ${{ needs.plan.outputs.prerelease }}
REF_NAME: ${{ github.ref_name }}
TARGET_SHA: ${{ github.sha }}
run: |
PRERELEASE_FLAG=""
if [ "${{ needs.plan.outputs.prerelease }}" = "true" ]; then
if [ "${PRERELEASE}" = "true" ]; then
PRERELEASE_FLAG="--prerelease"
fi

Expand All @@ -155,8 +169,8 @@

\`\`\`bash
# 1. Download the archive and its checksum
curl -sLO https://github.com/googleworkspace/cli/releases/download/${{ github.ref_name }}/google-workspace-cli-<target>.tar.gz
curl -sLO https://github.com/googleworkspace/cli/releases/download/${{ github.ref_name }}/google-workspace-cli-<target>.tar.gz.sha256
curl -sLO https://github.com/googleworkspace/cli/releases/download/${REF_NAME}/google-workspace-cli-<target>.tar.gz
curl -sLO https://github.com/googleworkspace/cli/releases/download/${REF_NAME}/google-workspace-cli-<target>.tar.gz.sha256

# 2. Verify the checksum
shasum -a 256 -c google-workspace-cli-<target>.tar.gz.sha256
Expand All @@ -176,44 +190,67 @@
---
"

gh release create "${{ github.ref_name }}" \
--target "${{ github.sha }}" \
--title "${{ github.ref_name }}" \
--notes "$NOTES" \
--generate-notes \
$PRERELEASE_FLAG \
artifacts/*
gh release create "${REF_NAME}" --target "${TARGET_SHA}" --title "${REF_NAME}" --notes "$NOTES" --generate-notes $PRERELEASE_FLAG artifacts/*

publish-npm:
needs: [plan, release]
runs-on: ubuntu-latest
if: ${{ needs.plan.outputs.publishing == 'true' && needs.plan.outputs.prerelease == 'false' }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '20.x'
registry-url: 'https://wombat-dressing-room.appspot.com'

- name: Publish to npm
- name: Authenticate to Google Cloud for OSS Exit Gate
id: auth
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
token_format: 'access_token'
workload_identity_provider: 'projects/305452601764/locations/global/workloadIdentityPools/builders/providers/github'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3

- name: Stage to Artifact Registry and trigger OSS Exit Gate
working-directory: npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
cat << 'NPMRC' > "$HOME/.npmrc"
registry=https://us-npm.pkg.dev/oss-exit-gate-prod/googleworkspace-cli--npm/
//us-npm.pkg.dev/oss-exit-gate-prod/googleworkspace-cli--npm/:always-auth=true
//us-npm.pkg.dev/oss-exit-gate-prod/googleworkspace-cli--npm/:_authToken=${ACCESS_TOKEN}
NPMRC
trap 'rm -f "$HOME/.npmrc"' EXIT
npm publish --access public --registry="https://us-npm.pkg.dev/oss-exit-gate-prod/googleworkspace-cli--npm/"
cat << 'MANIFEST' > manifest.json
{
"publish_all": true
}
MANIFEST
gcloud storage cp manifest.json "gs://oss-exit-gate-prod-projects-bucket/googleworkspace-cli/npm/manifests/manifest-${RUN_ID}-${RUN_ATTEMPT}.json"

publish-cargo:
needs: [plan, release]
runs-on: ubuntu-latest
if: ${{ needs.plan.outputs.publishing == 'true' && needs.plan.outputs.prerelease == 'false' }}
permissions:
contents: read
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable

# Publish library crate first (CLI depends on it)
- name: Publish google-workspace
run: cargo publish --package google-workspace

Check notice on line 253 in .github/workflows/release.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

use-trusted-publishing

release.yml:253: prefer trusted publishing for authentication: this command
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Expand All @@ -222,6 +259,6 @@
run: sleep 30

- name: Publish google-workspace-cli
run: cargo publish --package google-workspace-cli

Check notice on line 262 in .github/workflows/release.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

use-trusted-publishing

release.yml:262: prefer trusted publishing for authentication: this command
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Loading