-
Notifications
You must be signed in to change notification settings - Fork 12
91 lines (77 loc) · 3.63 KB
/
Copy pathpublish.yml
File metadata and controls
91 lines (77 loc) · 3.63 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
81
82
83
84
85
86
87
88
89
90
91
name: Publish to NPM
on:
workflow_call:
inputs:
updated:
description: 'JSON Array of updated packages'
required: true
type: string
permissions:
contents: write
env:
GRAPHQL_SCHEMA_FILE: '${{ github.workspace }}/schema.graphql'
jobs:
generate_schema:
name: Generate WPGraphQL schema
uses: './.github/workflows/generate-schema.yml'
with:
ref: 'main'
secrets: inherit
publish:
runs-on: ubuntu-latest
needs: generate_schema
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Authenticate with npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish to NPM
run: |
sudo apt install jq
declare -a package_array=($(echo '${{ inputs.updated }}' | jq -r '.[]'))
for package in "${package_array[@]}"; do
echo "Publishing $package"
location="$(npm query ".workspace#$package" | jq -r '.[0].location')"
version="$(npm query ".workspace#$package" | jq -r '.[0].version')"
private="$(npm query ".workspace#$package" | jq -r '.[0].private')"
if [ "$private" == "true" ]; then
echo "Skipping publishing private package $package"
tag_exists_on_github=$(gh api -X GET "/repos/${{ github.repository }}/releases/tags/$package@$version" &> /dev/null && echo true || echo false)
if [ "$tag_exists_on_github" == "true" ]; then
echo "Tag $package@$version already exists on GitHub. Skipping creating a new tag."
else
echo "Creating release $package@$version on GitHub"
bash '${{ github.workspace }}/.github/scripts/release_content.sh' "${{ github.workspace }}/$location/CHANGELOG.md" "$version"
gh release create "$package@$version" --title "$package@$version" --notes-file /tmp/changelog.md
fi
continue
else
npm publish --access public --workspace "$location" "$package"
# Make a GitHub Release
bash '${{ github.workspace }}/.github/scripts/release_content.sh' "${{ github.workspace }}/$location/CHANGELOG.md" "$version"
gh release create "$package@$version" --title "$package@$version" --notes-file /tmp/changelog.md
fi
done
git fetch origin main
git fetch origin develop --shallow-since="$(git log -1 --pretty=format:"%aI" origin/main)"
git pull --set-upstream origin develop:main
git push origin develop:main
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}