|
| 1 | +name: Code Foundry Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + issues: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +env: |
| 12 | + REPO_FOUNDRY_PROFILE: ${{ vars.REPO_FOUNDRY_PROFILE }} |
| 13 | + REPO_FOUNDRY_LANGUAGES: ${{ vars.REPO_FOUNDRY_LANGUAGES }} |
| 14 | + REPO_FOUNDRY_FEATURES: ${{ vars.REPO_FOUNDRY_FEATURES }} |
| 15 | + REPO_FOUNDRY_PACKAGE_MANAGER: ${{ vars.REPO_FOUNDRY_PACKAGE_MANAGER }} |
| 16 | + REPO_FOUNDRY_RELEASE_TYPE: ${{ vars.REPO_FOUNDRY_RELEASE_TYPE }} |
| 17 | + REPO_FOUNDRY_NPM_PUBLISH: ${{ vars.REPO_FOUNDRY_NPM_PUBLISH }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + release: |
| 21 | + name: Release / Version |
| 22 | + runs-on: ubuntu-slim |
| 23 | + timeout-minutes: 20 |
| 24 | + concurrency: |
| 25 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 26 | + cancel-in-progress: false |
| 27 | + outputs: |
| 28 | + release_created: ${{ steps.release.outputs.release_created || 'false' }} |
| 29 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 30 | + npm_publish: ${{ steps.profile.outputs.npm_publish }} |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v7 |
| 34 | + with: |
| 35 | + filter: blob:none |
| 36 | + - name: Detect release profile |
| 37 | + id: profile |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + if [ -x .github/scripts/profile.sh ]; then |
| 41 | + release_type="$(bash .github/scripts/profile.sh get release_type)" |
| 42 | + npm_publish="$(bash .github/scripts/profile.sh get npm_publish)" |
| 43 | + else |
| 44 | + release_type="$(awk -F': ' '/^release_type:/ {print $2; exit}' .github/template.yml 2>/dev/null || true)" |
| 45 | + npm_publish="$(awk -F': ' '/^npm_publish:/ {print $2; exit}' .github/template.yml 2>/dev/null || true)" |
| 46 | + fi |
| 47 | + [ -n "$release_type" ] || release_type=auto |
| 48 | + [ -n "$npm_publish" ] || npm_publish=false |
| 49 | +
|
| 50 | + if [ "$release_type" = auto ]; then |
| 51 | + if [ -f package.json ]; then release_type=node |
| 52 | + elif [ -f pyproject.toml ]; then release_type=python |
| 53 | + elif [ -f Cargo.toml ]; then release_type=rust |
| 54 | + elif [ -f version.txt ]; then release_type=simple |
| 55 | + else release_type=none |
| 56 | + fi |
| 57 | + fi |
| 58 | +
|
| 59 | + case "$release_type" in |
| 60 | + node|python|rust|simple) ;; |
| 61 | + none) npm_publish=false ;; |
| 62 | + *) echo "Unsupported release_type: $release_type" >&2; exit 2 ;; |
| 63 | + esac |
| 64 | + if [ ! -f package.json ]; then npm_publish=false; fi |
| 65 | + printf 'release_type=%s\n' "$release_type" >> "$GITHUB_OUTPUT" |
| 66 | + printf 'npm_publish=%s\n' "$npm_publish" >> "$GITHUB_OUTPUT" |
| 67 | + - name: Release Please |
| 68 | + id: release |
| 69 | + if: steps.profile.outputs.release_type != 'none' |
| 70 | + uses: googleapis/release-please-action@v5 |
| 71 | + with: |
| 72 | + token: ${{ secrets.RELEASE_PLEASE_TOKEN || github.token }} |
| 73 | + config-file: release-please-config.json |
| 74 | + release-type: ${{ steps.profile.outputs.release_type }} |
| 75 | + |
| 76 | + npm: |
| 77 | + name: Release / Publish npm |
| 78 | + needs: release |
| 79 | + if: needs.release.outputs.release_created == 'true' && needs.release.outputs.npm_publish == 'true' |
| 80 | + runs-on: ubuntu-slim |
| 81 | + timeout-minutes: 15 |
| 82 | + permissions: |
| 83 | + contents: read |
| 84 | + id-token: write |
| 85 | + env: |
| 86 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 87 | + steps: |
| 88 | + - name: Checkout release |
| 89 | + uses: actions/checkout@v7 |
| 90 | + with: |
| 91 | + ref: ${{ needs.release.outputs.tag_name }} |
| 92 | + - name: Setup Node (trusted) |
| 93 | + if: env.NPM_TOKEN == '' |
| 94 | + uses: actions/setup-node@v5 |
| 95 | + with: |
| 96 | + node-version: 24 |
| 97 | + - name: Setup Node (token) |
| 98 | + if: env.NPM_TOKEN != '' |
| 99 | + uses: actions/setup-node@v5 |
| 100 | + with: |
| 101 | + node-version: 24 |
| 102 | + registry-url: https://registry.npmjs.org |
| 103 | + - name: Publish npm with token |
| 104 | + if: env.NPM_TOKEN != '' |
| 105 | + env: |
| 106 | + NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} |
| 107 | + run: npm publish --provenance --access public |
| 108 | + - name: Publish npm with trusted publishing |
| 109 | + if: env.NPM_TOKEN == '' |
| 110 | + run: npm publish --provenance --access public |
0 commit comments