|
1 |
| -name: Docker Images |
| 1 | +name: Prerelease litlytics library |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | workflow_run:
|
|
9 | 9 | branches:
|
10 | 10 | - main # Only run the publish workflow for pushes to main
|
11 | 11 |
|
12 |
| -env: |
13 |
| - # Use docker.io for Docker Hub if empty |
14 |
| - REGISTRY: ghcr.io |
15 |
| - # github.repository as <account>/<repo> |
16 |
| - IMAGE_NAME: ${{ github.repository }} |
17 |
| - |
18 | 12 | jobs:
|
19 |
| - build: |
| 13 | + publish-lib: |
20 | 14 | environment: Github CI
|
| 15 | + # Only proceed if the tests passed and we're on release |
| 16 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} && startsWith(github.head_ref, 'refs/tags/') == true |
21 | 17 | runs-on: ubuntu-latest
|
22 | 18 | permissions:
|
23 | 19 | contents: read
|
24 |
| - packages: write |
25 | 20 | id-token: write
|
26 | 21 |
|
27 | 22 | steps:
|
28 | 23 | - name: Checkout repository
|
29 | 24 | uses: actions/checkout@v4
|
30 | 25 |
|
31 |
| - - name: Install bun for deployment |
32 |
| - uses: oven-sh/setup-bun@v2 |
33 |
| - with: |
34 |
| - bun-version: latest |
35 |
| - |
36 |
| - # Login against a Docker registry |
37 |
| - # https://github.com/docker/login-action |
38 |
| - - name: Log into registry ${{ env.REGISTRY }} |
39 |
| - uses: docker/login-action@v3 |
40 |
| - with: |
41 |
| - registry: ${{ env.REGISTRY }} |
42 |
| - username: ${{ github.actor }} |
43 |
| - password: ${{ secrets.GITHUB_TOKEN }} |
44 |
| - |
45 |
| - # Extract metadata (tags, labels) for Docker |
46 |
| - # https://github.com/docker/metadata-action |
47 |
| - - name: Extract Docker metadata |
48 |
| - id: meta |
49 |
| - uses: docker/metadata-action@v5 |
50 |
| - with: |
51 |
| - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
52 |
| - |
53 |
| - # Conditional tagging based on the event type (main push or release) |
54 |
| - - name: Determine image tags |
55 |
| - id: tags |
| 26 | + # Check for changes in ./packages/litlytics |
| 27 | + - name: Check if changed |
| 28 | + id: changes |
56 | 29 | run: |
|
57 |
| - if [[ "${{ github.event_name }}" == "release" ]]; then |
58 |
| - # Tag as `latest` and `vX.X.X` for releases |
59 |
| - echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}" >> $GITHUB_ENV |
| 30 | + # Check if any files changed in the specified directory |
| 31 | + if git diff --quiet HEAD^ HEAD ./packages/litlytics; then |
| 32 | + echo "No changes in ./packages/litlytics. Skipping publish." |
| 33 | + echo "should_publish=false" >> $GITHUB_ENV |
60 | 34 | else
|
61 |
| - # Tag as `nightly` for pushes to main |
62 |
| - echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly" >> $GITHUB_ENV |
| 35 | + echo "Changes detected in ./packages/litlytics." |
| 36 | + echo "should_publish=true" >> $GITHUB_ENV |
63 | 37 | fi
|
64 |
| - shell: bash |
65 | 38 |
|
66 |
| - # Build and push Docker image with Buildx |
67 |
| - # https://github.com/docker/build-push-action |
68 |
| - - name: Build and push Docker image |
69 |
| - id: build-and-push |
70 |
| - uses: docker/build-push-action@v6 |
| 39 | + # install node (for npm utils) |
| 40 | + - name: Install node for npm checks |
| 41 | + uses: actions/setup-node@v4 |
71 | 42 | with:
|
72 |
| - push: true |
73 |
| - tags: ${{ env.TAGS }} |
74 |
| - labels: ${{ steps.meta.outputs.labels }} |
| 43 | + node-version: 22 |
| 44 | + registry-url: 'https://registry.npmjs.org' |
75 | 45 |
|
76 |
| - # deploy nightly |
77 |
| - - name: Deploy docker image to staging |
78 |
| - if: github.event_name != 'release' |
79 |
| - env: |
80 |
| - EXO_TOKEN: ${{ secrets.EXO_TOKEN }} |
81 |
| - run: bunx exoframe -u -c exoframe-nightly.json -e https://exoframe.codezen.net -t $EXO_TOKEN |
| 46 | + # install bun |
| 47 | + - name: Install bun for deployment |
| 48 | + uses: oven-sh/setup-bun@v2 |
| 49 | + with: |
| 50 | + bun-version: latest |
| 51 | + |
| 52 | + # Install dependencies |
| 53 | + - name: Install dependencies |
| 54 | + working-directory: ./packages/litlytics |
| 55 | + run: bun install --frozen-lockfile |
| 56 | + |
| 57 | + # Build package |
| 58 | + - name: Build package |
| 59 | + working-directory: ./packages/litlytics |
| 60 | + run: bun run build |
82 | 61 |
|
83 |
| - # deploy to prod |
84 |
| - - name: Deploy docker image to production |
85 |
| - if: github.event_name == 'release' |
| 62 | + # install and publish if local version is not the same as published |
| 63 | + - name: publish |
| 64 | + if: ${{ env.should_publish == 'true' }} |
| 65 | + working-directory: ./packages/litlytics |
| 66 | + run: npm publish --access public |
86 | 67 | env:
|
87 |
| - EXO_TOKEN: ${{ secrets.EXO_TOKEN }} |
88 |
| - run: bunx exoframe -u -e https://exoframe.codezen.net -t $EXO_TOKEN |
| 68 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments