Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: adds workflows to release and publish new versions of packages #24

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/scripts/generate_release_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import json
import os

#
# // PULL_LABELS = toJson(github.event.pull_request.labels)
#
# [
# {
# "color": "FFFFF7",
# "default": false,
# "description": "Issue describes change in the development process",
# "id": 1786730933,
# "name": "label_pqr-xyz-release",
# "node_id": "MDU6TGFiZWwxNzg2NzMwOTMz",
# "url": "https://api.github.com/repos/parzh/parzh.github.io/labels/Domain:%20dev"
# },
# {
# "color": "cc062a",
# "default": false,
# "description": "Issue must be addressed right now",
# "id": 1786706637,
# "name": "label_abc-release",
# "node_id": "MDU6TGFiZWwxNzg2NzA2NjM3",
# "url": "https://api.github.com/repos/parzh/parzh.github.io/labels/Priority:%20top"
# },
# {
# "color": "00727C",
# "default": false,
# "description": "Issue describes lack of a functionality or an open possibility of enhancement",
# "id": 1786726751,
# "name": "label_123-improvement",
# "node_id": "MDU6TGFiZWwxNzg2NzI2NzUx",
# "url": "https://api.github.com/repos/parzh/parzh.github.io/labels/Type:%20improvement"
# }
# ]
#
# Test:
# PULL_LABELS=$(cat labels.json) python3 generate_release_matrix.py
#

try:
labels = json.loads(os.getenv('PULL_LABELS'))
except:
labels = []

trigger_substring = "-release"
matrix = []
hasLabels = False
for label in labels:
label_name = str(label['name'])
trigger_substring_index = label_name.find(trigger_substring)
if trigger_substring_index != -1:
matrix.append({
'package': label_name[:trigger_substring_index],
})
hasLabels = True

print(json.dumps({'include': matrix}))
71 changes: 71 additions & 0 deletions .github/workflows/subgraph-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Subgraph Publish

on:
push:
tags:
- '*'

jobs:
check_tag:
runs-on: ubuntu-latest
outputs:
package: ${{ steps.tag-info.outputs.package }}
version: ${{ steps.tag-info.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get version from Github Tag
id: tag-info
run: |
GITHUB_REF="${{ github.ref }}"
if [[ "$GITHUB_REF" == *"subgraph"* ]]; then
TAG=${GITHUB_REF##*/}
VERSION=$(echo "$TAG" | grep -woP "([0-9]+\.[0-9]+\.[0-9]+)-\w+" | sed 's/-javascript//')
PACKAGE=subgraph
fi

publish:
runs-on: ubuntu-latest
needs: [check_tag]
if: ${{ needs.check_tag.outputs.package }}
steps:
- name: Validate values (package and version) from Github Tag
run: |
if [ -z "${{ needs.check_tag.outputs.package }}" ]; then
echo "::error ::No package found in tag"
exit 1
fi
if [ -z "${{ needs.check_tag.outputs.version }}" ]; then
echo "::error ::No version found in tag"
exit 1
fi
- name: Checkout code
uses: actions/checkout@v3
with:
ref: 'develop'
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 18.x
registry-url: https://registry.npmjs.org
- name: Publish NPM pkg (${{ needs.check_tag.outputs.package }} - ${{ needs.check_tag.outputs.version }})
run: yarn publish --no-git-tag-version --new-version ${{ needs.check_tag.outputs.version }}
working-directory: ./${{ needs.check_tag.outputs.package }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Setup Python environment
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
package: ${{ needs.check_tag.outputs.package }}
version: ${{ needs.check_tag.outputs.version }}
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="$package - $version" \
--generate-notes
66 changes: 66 additions & 0 deletions .github/workflows/subgraph-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 01-JS-Release

on:
pull_request:
types:
- closed

jobs:
prepare:
name: Prepare release generation
runs-on: ubuntu-latest
if: github.event.pull_request.merged
outputs:
PACKAGE_LIST: ${{ steps.matrix.outputs.pkg_list }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: 'develop'
- name: Setup Python environment
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Get package-list from label-list
id: matrix
run: |
PKG_LIST=$(python ./.github/scripts/generate_release_matrix.py)
PR_LABEL_LIST="${{ toJson(github.event.pull_request.labels.*.name) }}"
echo "Pkg list: $PKG_LIST"
echo "Label list: $PR_LABEL_LIST"
echo "pkg_list=$PKG_LIST" >> $GITHUB_OUTPUT
env:
PULL_LABELS: ${{ toJson(github.event.pull_request.labels) }}

release:
name: Set Github Tag
runs-on: ubuntu-latest
needs: [prepare]
## This condition gets TRUE if used in this way: ${{ contains(toJson(xyz), 'substr') }}
if: ${{ contains( toJson(github.event.pull_request.labels.*.name), '-release' ) }}
strategy:
fail-fast: true
matrix: ${{ fromJson(needs.prepare.outputs.PACKAGE_LIST) }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: 'develop'
- name: Get version from '${{ matrix.package }}' package.json
id: getver
working-directory: './modules/${{ matrix.package }}'
run: |
VERSION=$(cat package.json | jq -r .version)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Set Github Tag via API
uses: actions/github-script@v6
with:
github-token: ${{ secrets.ARABOT_PAT_TRIGGER_WORKFLOW }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${{ steps.getver.outputs.version }}-${{ matrix.package }}`,
sha: "${{ github.sha }}"
})