forked from divviup/janus
-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (77 loc) · 2.64 KB
/
Copy pathpublish-sql-schema.yml
File metadata and controls
80 lines (77 loc) · 2.64 KB
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
name: publish-sql-schema
on:
release:
types: [published]
workflow_dispatch:
inputs:
force:
description: force overwrite of migrations
default: false
required: false
type: boolean
jobs:
push-schema:
permissions:
id-token: "write"
contents: "read"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: "gcp-auth"
name: "Authenticate to GCP"
uses: "google-github-actions/auth@v1"
with:
workload_identity_provider: ${{ vars.GCP_ARTIFACT_PUBLISHER_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GCP_ARTIFACT_PUBLISHER_DEPLOY_SERVICE_ACCOUNT }}
create_credentials_file: true
export_environment_variables: true
- name: Configure rclone
run: |
sudo apt-get install rclone
mkdir -p ~/.config/rclone
cat >~/.config/rclone/rclone.conf <<-EOF
[gs]
type = google cloud storage
env_auth = true
bucket_policy_only = true
EOF
- name: Get the version
id: get_version
run: |
if grep -P "^refs/tags/" <<<"$GITHUB_REF" >/dev/null; then
VERSION=${GITHUB_REF/refs\/tags\//}
MINOR_VERSION="$(echo "$VERSION" | awk -F'.' '{if (NF != 3) {exit 1}; printf "%s.%s", $1, $2}')"
echo "version=$MINOR_VERSION" >>"$GITHUB_OUTPUT"
elif grep -P "^refs/heads/" <<<"$GITHUB_REF" >/dev/null; then
BRANCH=${GITHUB_REF/refs\/heads\//}
echo "version=$BRANCH" >>"$GITHUB_OUTPUT"
else
echo "Unable to parse version information"
exit 1
fi
- name: Check validity of migrations
uses: "./.github/actions/validate-migrations"
- name: Check that existing migrations have not changed
if: '!inputs.force'
run: |
TEMP=$(mktemp -d)
rclone copy --verbose \
"gs:/janus-artifacts-sql-schemas/${{ steps.get_version.outputs.version }}/db/" \
"$TEMP"
# --diff-filter=a includes all differences except added files.
if ! git diff --no-index --diff-filter=a "$TEMP/" "./db"; then
echo "fatal: migrations cannot be modified or removed, only added"
exit 1
fi
- name: "Upload schema file(s)"
if: '!inputs.force'
run: |-
rclone copy --ignore-existing --verbose \
"db/" \
"gs://janus-artifacts-sql-schemas/${{ steps.get_version.outputs.version }}/db/"
- name: "Overwrite schema file(s)"
if: inputs.force
run: |-
rclone sync --verbose \
"db/" \
"gs://janus-artifacts-sql-schemas/${{ steps.get_version.outputs.version }}/db/"