-
Notifications
You must be signed in to change notification settings - Fork 14
138 lines (116 loc) · 4.79 KB
/
packages_release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Packages Release
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release-packages:
name: Release Packages
runs-on: ubuntu-latest
outputs:
imagePackageReleaseCreated: ${{ steps.check_image_package_release.outputs.release_created }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Add NPM auth
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> ~/.npmrc
- name: Install dependencies
run: pnpm install
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Check if @powersync/service-image Released
id: check_image_package_release
if: steps.changesets.outputs.published == 'true'
run: |
packages="${{ toJson(steps.changesets.outputs.publishedPackages) }}"
echo "Packages: $packages" # Debugging output
# Use jq to check if the specific package is in the array
# Ensure the JSON is valid by echoing it into jq
set +e # Disable immediate exit on non-zero return
echo "$packages" | jq -e '[.[] | select(.name == "@powersync/service-image")] | length > 0' > /dev/null
jq_exit_code=$?
set -e # Re-enable immediate exit
if [ $jq_exit_code -eq 0 ]; then
echo "release_created=true" >> $GITHUB_OUTPUT
else
echo "release_created=false" >> $GITHUB_OUTPUT
fi
- name: Debug Outputs
run: |
echo "Published Packages: ${{ steps.changesets.outputs.publishedPackages }}"
echo "Released Docker Image: ${{ steps.check_image_package_release.outputs.release_created }}"
release-docker-image:
name: Build and Release powersync-service Docker Image
runs-on: ubuntu-latest
needs: release-packages
# Only run this job if the previous release job created a release for @powersync/service-image
if: needs.release-packages.outputs.imagePackageReleaseCreated == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# check out full history
# Temporarily needed for changesets
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# This uses the service's package.json version for the Docker Image tag
- name: Get Service Version from package.json
id: get_version
run: echo "SERVICE_VERSION=$(node -p "require('./service/package.json').version")" >> $GITHUB_OUTPUT
- name: Build Image and Push
uses: docker/build-push-action@v5
with:
platforms: linux/arm64,linux/amd64
cache-from: type=registry,ref=${{vars.DOCKER_REGISTRY}}:latest
context: .
tags: ${{vars.DOCKER_REGISTRY}}:latest,${{vars.DOCKER_REGISTRY}}:${{steps.get_version.outputs.SERVICE_VERSION}}
push: true
file: ./service/Dockerfile
# # Updates the README section on the DockerHub page
- name: Update repo description
# Note that this 3rd party extention is recommended in the DockerHub docs:
# https://docs.docker.com/build/ci/github-actions/update-dockerhub-desc/
uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{vars.DOCKER_REGISTRY}}
# This is the contents of what will be shown on DockerHub
readme-filepath: ./service/README.md