|
| 1 | +name: Release New Version |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + version: |
| 6 | + description: "The version to release" |
| 7 | + required: false |
| 8 | + default: "" |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: release-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +env: |
| 15 | + SVU_VERSION: "3.3.3" |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-with-latest-hapi-release: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Import Vault Credentials |
| 26 | + id: import-secrets |
| 27 | + uses: spectrocloud/palette-sdk-typescript/.github/actions/vault-credentials@main |
| 28 | + |
| 29 | + - name: Checkout |
| 30 | + |
| 31 | + with: |
| 32 | + token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }} |
| 33 | + |
| 34 | + - name: Setup Node.js environment |
| 35 | + |
| 36 | + with: |
| 37 | + node-version: "22" |
| 38 | + cache: "npm" |
| 39 | + registry-url: "https://npm.pkg.github.com" |
| 40 | + |
| 41 | + - name: Setup Copywrite |
| 42 | + |
| 43 | + |
| 44 | + - name: Checkout HAPI Repository |
| 45 | + |
| 46 | + with: |
| 47 | + repository: spectrocloud/hapi |
| 48 | + path: api/hapi |
| 49 | + fetch-depth: "0" |
| 50 | + token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + run: make install-dependencies |
| 54 | + |
| 55 | + - name: Install Go Swagger |
| 56 | + run: | |
| 57 | + dir=$(mktemp -d) |
| 58 | + download_url=$(curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/latest | \ |
| 59 | + jq -r '.assets[] | select(.name | contains("'"$(uname | tr '[:upper:]' '[:lower:]')"'_amd64")) | .browser_download_url') |
| 60 | + curl -o $dir/swagger -L'#' "$download_url" |
| 61 | + sudo install $dir/swagger /usr/local/bin |
| 62 | +
|
| 63 | + - name: Ensure Reviewable |
| 64 | + run: make check-diff |
| 65 | + |
| 66 | + - name: Generate |
| 67 | + run: make generate |
| 68 | + |
| 69 | + - name: Test |
| 70 | + env: |
| 71 | + # Expires 2026-12-31. Tenant is https://palette-ai-rsch.console.spectrocloud.com/ |
| 72 | + PALETTE_API_KEY: ${{ secrets.PALETTE_API_KEY }} |
| 73 | + run: make test |
| 74 | + |
| 75 | + - name: Get svu |
| 76 | + run: | |
| 77 | + URL="https://github.com/caarlos0/svu/releases/download/v${SVU_VERSION}/svu_${SVU_VERSION}_linux_amd64.tar.gz" |
| 78 | + wget --quiet $URL --output-document svu.tar.gz |
| 79 | + tar -xzf svu.tar.gz |
| 80 | + chmod +x svu |
| 81 | + sudo mv svu /usr/local/bin/ |
| 82 | + svu --version |
| 83 | +
|
| 84 | + - id: tag |
| 85 | + run: | |
| 86 | + INPUT_VERSION="${{ github.event.inputs.version }}" |
| 87 | +
|
| 88 | + if [ -n "$INPUT_VERSION" ]; then |
| 89 | + echo "Using provided version: $INPUT_VERSION" |
| 90 | + VERSION="$INPUT_VERSION" |
| 91 | + PREV_VERSION=$(svu current --tag.mode all) |
| 92 | + echo "SAME_VERSION=false" >> $GITHUB_OUTPUT |
| 93 | +
|
| 94 | + # Check if the tag already exists before creating it |
| 95 | + if git rev-parse "$VERSION" >/dev/null 2>&1; then |
| 96 | + echo "Tag $VERSION already exists, skipping tag creation." |
| 97 | + else |
| 98 | + git tag "$VERSION" |
| 99 | + git push --tags |
| 100 | + fi |
| 101 | + else |
| 102 | + VERSION=$(svu next --tag.mode all) |
| 103 | + PREV_VERSION=$(svu current --tag.mode all) |
| 104 | +
|
| 105 | + if [ "$VERSION" = "$PREV_VERSION" ]; then |
| 106 | + echo "no new version detected" |
| 107 | + SAME_VERSION=true |
| 108 | + echo "SAME_VERSION=true" >> $GITHUB_OUTPUT |
| 109 | + else |
| 110 | + echo "new version detected" |
| 111 | + SAME_VERSION=false |
| 112 | + echo "SAME_VERSION=false" >> $GITHUB_OUTPUT |
| 113 | +
|
| 114 | + # Check if the tag already exists before creating it |
| 115 | + if git rev-parse "$VERSION" >/dev/null 2>&1; then |
| 116 | + echo "Tag $VERSION already exists, skipping tag creation." |
| 117 | + else |
| 118 | + git tag "$VERSION" |
| 119 | + git push --tags |
| 120 | + fi |
| 121 | + fi |
| 122 | + fi |
| 123 | +
|
| 124 | + # Strip v prefix for npm version |
| 125 | + NPM_VERSION="${VERSION#v}" |
| 126 | +
|
| 127 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 128 | + echo "NPM_VERSION=$NPM_VERSION" >> $GITHUB_OUTPUT |
| 129 | + echo "PREV_VERSION=$PREV_VERSION" >> $GITHUB_OUTPUT |
| 130 | +
|
| 131 | + - name: Set package version |
| 132 | + if: steps.tag.outputs.SAME_VERSION != 'true' |
| 133 | + run: npm version ${{ steps.tag.outputs.NPM_VERSION }} --no-git-tag-version |
| 134 | + |
| 135 | + - name: Publish to npm |
| 136 | + if: steps.tag.outputs.SAME_VERSION != 'true' |
| 137 | + run: npm publish |
| 138 | + env: |
| 139 | + NODE_AUTH_TOKEN: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }} |
| 140 | + |
| 141 | + - name: Commit reviewable diff |
| 142 | + if: steps.tag.outputs.SAME_VERSION != 'true' |
| 143 | + uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7 |
| 144 | + with: |
| 145 | + commit_message: "chore: release ${{ steps.tag.outputs.VERSION }}" |
0 commit comments