-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to automatically create new node release (#485)
* manual node version-up * test on PR first * test on PR first * test signing of commit * use chromeq/commit@v2.x * revert to use swinton/commit * use back chromeq, but without the env * use graphql instead * add reviewers * add commit list and release node workflow * add api and commit on: all, node, or all but the node * add a script to specify a specifiv version number to upgrade the crates * #485 (comment) * add label on newly created PR; use that label for triggering the release yml * add comments to easily understand the workflow * #485 (comment) * execute gitlab * change PR title * remove new lines * run with ``--release`
- Loading branch information
Showing
8 changed files
with
301 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
mutation ( | ||
$githubRepository: String!, | ||
$branchName: String!, | ||
$expectedHeadOid: GitObjectID! | ||
$commitMessage: String! | ||
$files: [FileAddition!]! | ||
) { | ||
createCommitOnBranch( | ||
input: { | ||
branch: | ||
{ | ||
repositoryNameWithOwner: $githubRepository, | ||
branchName: $branchName | ||
}, | ||
message: {headline: $commitMessage}, | ||
fileChanges: { | ||
additions: $files | ||
} | ||
expectedHeadOid: $expectedHeadOid | ||
} | ||
){ | ||
commit { | ||
url | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# define the version number we want to set | ||
newVersion=$1 | ||
|
||
# Find all Cargo.toml files in the current directory and its subdirectories | ||
for file in $(find . -name "Cargo.toml") | ||
do | ||
# Use awk to change the version number of the package | ||
awk -v newVersion="$newVersion" -F'=' '/\[package\]/,/version =/ { if($0 ~ /version =/ && $0 !~ /#/) {print $1 "= ""\""newVersion"\""; next} }1' $file > temp && mv temp $file | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
runtime=$1 | ||
versionName=$2 | ||
|
||
if [ $runtime == "amplitude" ]; then | ||
file="runtime/amplitude/src/lib.rs" | ||
elif [ $runtime == "pendulum" ]; then | ||
file="runtime/pendulum/src/lib.rs" | ||
fi | ||
|
||
echo "increment: $versionName" | ||
# Use awk to increment the version of the lib | ||
awk -v pat="$versionName" -F':' '$0~pat { {print $1": " $2+1","; next} }1' $file > temp && mv temp $file | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This action triggers a GitLab CI job that generates the release notes | ||
name: Node Release | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- 'main' | ||
|
||
jobs: | ||
release_check: | ||
# This job will only run if: | ||
# * the pull request is closed and merged to main branch; | ||
# * the pull request has the label "release-node" | ||
if: ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release-node') }} | ||
name: Need new release | ||
strategy: | ||
fail-fast: true | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get Node Version | ||
id: get-version | ||
run: | | ||
vers=$( cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "pendulum-node") | .version' | tr -d '"' ) | ||
echo "version=${vers}" >> "$GITHUB_OUTPUT" | ||
- name: trigger gitlab | ||
run: | | ||
ls ${{ github.workspace }} | ||
curl -X POST -F "token=${{ secrets.GITLAB_TRIGGER }}" -F "ref=development" -F "variables[PREPCOMPILE]=Y" -F "variables[COMPILE]=Y" -F "variables[COMPILEMOONBEAM]=N" -F "variables[DOCKER]=Y" -F "variables[DOCKERAMP]=Y" -F "variables[DEBIAN]=Y" -F "variables[TEMPUPLOAD]=Y" -F "variables[DOWNUPLOAD]=Y" -F "variables[PRODUPLOAD]=Y" -F "variables[VERSION]=${{ steps.get-version.outputs.version }}" https://gitlab.com/api/v4/projects/${{ secrets.PROJECT_ID }}/trigger/pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
name: Version Up | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
versioning: | ||
type: choice | ||
description: "choose versioning:" | ||
options: | ||
- major | ||
- minor | ||
- patch | ||
- release | ||
- rc | ||
- beta | ||
- alpha | ||
specific_version: | ||
type: string | ||
description: "Specific version to bump to. If specified, the versioning input will be ignored" | ||
packages-all: | ||
description: "Check if ALL packages will be updated. Else, only pendulum-node" | ||
required: false | ||
type: boolean | ||
default: true | ||
|
||
jobs: | ||
bump-version: | ||
runs-on: ubuntu-latest | ||
name: bump version | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup User | ||
run: | | ||
git config user.name github-actions | ||
git config user.email github-actions@github.com | ||
# Install cargo-edit if specific version is NOT provided | ||
- name: install cargo-edit | ||
if: github.event.inputs.specific_version == '' | ||
run: | | ||
cargo install cargo-edit | ||
- name: Check For Specific Version | ||
if: github.event.inputs.specific_version != '' | ||
run: | | ||
bash .github/scripts/package_version_up ${{ github.event.inputs.specific_version }} | ||
if ${{ github.event.inputs.packages-all }} == 'true'; then | ||
echo "Upgrading crates to ${{ github.event.inputs.specific_version }}" &> changes.txt | ||
else | ||
echo "Upgrading node to ${{ github.event.inputs.specific_version }}" &> changes.txt | ||
fi | ||
- name: ${{ github.event.inputs.versioning }} Version Up for all | ||
if: github.event.inputs.specific_version == '' && github.event.inputs.packages-all == 'true' | ||
continue-on-error: false | ||
run: | | ||
cargo set-version --bump ${{ github.event.inputs.versioning }} &> changes.txt | ||
cat changes.txt | ||
- name: ${{ github.event.inputs.versioning }} Version Up for node | ||
if: github.event.inputs.specific_version == '' && github.event.inputs.packages-all == 'false' | ||
continue-on-error: false | ||
run: | | ||
cargo set-version --bump ${{ github.event.inputs.versioning }} --package pendulum-node &> changes.txt | ||
cat changes.txt | ||
- name: "Read file contents" | ||
id: read-file | ||
uses: juliangruber/read-file-action@v1 | ||
with: | ||
path: ./changes.txt | ||
|
||
- name: Set Chosen Package | ||
id: set-pkg | ||
run: | | ||
if [ ${{ github.event.inputs.packages-all }} == 'true' ]; then | ||
echo "name=all" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "name=node" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Put current date into a variable | ||
id: date-now | ||
uses: Kaven-Universe/github-action-current-date-time@v1 | ||
with: | ||
format: "yyyy-MM-dd" | ||
|
||
- name: Create Release Branch | ||
id: new-branch | ||
run: | | ||
name=${{ steps.set-pkg.outputs.name }} | ||
now="${{ steps.date-now.outputs.day }}-${{ steps.date-now.outputs.month }}-${{ steps.date-now.outputs.year }}" | ||
if [ '${{ github.event.inputs.specific_version }}' != '' ]; then | ||
echo "specific version: ${{ github.event.inputs.specific_version }}" | ||
branch_name="release/version-up-to-${{ github.event.inputs.specific_version }}-$name-$now" | ||
else | ||
vers=${{ github.event.inputs.versioning }} | ||
echo "versioning: ${{ github.event.inputs.versioning }}" | ||
branch_name="release/$vers-version-up-$name-$now" | ||
fi | ||
echo "name=${branch_name}" >> "$GITHUB_OUTPUT" | ||
git checkout -b ${branch_name} | ||
git push --set-upstream origin ${branch_name} | ||
# todo: make this simpler. | ||
- name: Commit New Changes to New Branch (all) | ||
if: github.event.inputs.packages-all == 'true' | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: ${{ steps.new-branch.outputs.name }} | ||
run: | | ||
gh api graphql \ | ||
-F githubRepository=${{ github.repository }} \ | ||
-F branchName=${{ env.BRANCH }} \ | ||
-F expectedHeadOid=$(git rev-parse HEAD) \ | ||
-F commitMessage="$(cat changes.txt)" \ | ||
-F files[][path]="chain-extensions/common/Cargo.toml" -F files[][contents]=$(base64 -w0 chain-extensions/common/Cargo.toml) \ | ||
-F files[][path]="chain-extensions/price/Cargo.toml" -F files[][contents]=$(base64 -w0 chain-extensions/price/Cargo.toml) \ | ||
-F files[][path]="chain-extensions/token/Cargo.toml" -F files[][contents]=$(base64 -w0 chain-extensions/token/Cargo.toml) \ | ||
-F files[][path]="node/Cargo.toml" -F files[][contents]=$(base64 -w0 node/Cargo.toml) \ | ||
-F files[][path]="pallets/orml-currencies-allowance-extension/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/orml-currencies-allowance-extension/Cargo.toml) \ | ||
-F files[][path]="pallets/orml-tokens-management-extension/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/orml-tokens-management-extension/Cargo.toml) \ | ||
-F files[][path]="pallets/parachain-staking/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/parachain-staking/Cargo.toml) \ | ||
-F files[][path]="pallets/parachain-staking/rpc/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/parachain-staking/rpc/Cargo.toml) \ | ||
-F files[][path]="pallets/parachain-staking/rpc/runtime-api/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/parachain-staking/rpc/runtime-api/Cargo.toml) \ | ||
-F files[][path]="pallets/treasury-buyout-extension/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/treasury-buyout-extension/Cargo.toml) \ | ||
-F files[][path]="pallets/vesting-manager/Cargo.toml" -F files[][contents]=$(base64 -w0 pallets/vesting-manager/Cargo.toml) \ | ||
-F files[][path]="runtime/amplitude/Cargo.toml" -F files[][contents]=$(base64 -w0 runtime/amplitude/Cargo.toml) \ | ||
-F files[][path]="runtime/common/Cargo.toml" -F files[][contents]=$(base64 -w0 runtime/common/Cargo.toml) \ | ||
-F files[][path]="runtime/foucoco/Cargo.toml" -F files[][contents]=$(base64 -w0 runtime/foucoco/Cargo.toml) \ | ||
-F files[][path]="runtime/integration-tests/Cargo.toml" -F files[][contents]=$(base64 -w0 runtime/integration-tests/Cargo.toml) \ | ||
-F files[][path]="runtime/pendulum/Cargo.toml" -F files[][contents]=$(base64 -w0 runtime/pendulum/Cargo.toml) \ | ||
-F 'query=@.github/api/createCommitOnBranch.gql' | ||
- name: Commit New Changes to New Branch (node) | ||
if: github.event.inputs.packages-all == 'false' | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: ${{ steps.new-branch.outputs.name }} | ||
run: | | ||
gh api graphql \ | ||
-F githubRepository=${{ github.repository }} \ | ||
-F branchName=${{ env.BRANCH }} \ | ||
-F expectedHeadOid=$(git rev-parse HEAD) \ | ||
-F commitMessage="$(cat changes.txt)" \ | ||
-F files[][path]="node/Cargo.toml" -F files[][contents]=$(base64 -w0 node/Cargo.toml) \ | ||
-F 'query=@.github/api/createCommitOnBranch.gql' | ||
- name: Prepare Pull Request title | ||
id: pr-title | ||
run: | | ||
if ${{ github.event.inputs.specific_version }} == ''; then | ||
echo "title=release: Bump ${{ steps.set-pkg.outputs.name }} crate version/s to ${{ github.event.inputs.versioning }}" >> "$GITHUB_OUTPUT" | ||
else | ||
vers=$( cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "pendulum-node") | .version' | tr -d '"' ) | ||
echo "title=release: Force bump ${{ steps.set-pkg.outputs.name }} version/s to $vers" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Create Pull Request | ||
uses: thomaseizinger/create-pull-request@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
title: ${{ steps.pr-title.outputs.title }} | ||
body: ${{ steps.read-file.outputs.content }} | ||
head: ${{ steps.new-branch.outputs.name }} | ||
base: main | ||
reviewers: "pendulum-chain/devs" | ||
labels: release-node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
versionNumber=$1 | ||
|
||
tagNamePrefix="node-release" | ||
## get the latest tag of this node | ||
lastVersionName=$(git describe --abbrev=0 --tags --always `git rev-list --tags` | grep -i "$tagNamePrefix" -m 1) | ||
|
||
## get the commits since the last tag | ||
latestCommitOfLastVersion=$(git log $lastVersionName --oneline --max-count=1 | cut -c1-7) | ||
|
||
|
||
logs=( $(git log $latestCommitOfLastVersion..origin/main --oneline -- node/ | cut -c1-7) ) | ||
if (( ${#logs[@]} == 0 )); then | ||
echo "Error: Repo is up to date. No new release required". | ||
exit 1 | ||
fi | ||
|
||
echo -e "## What's Changed\n" >> Commits.txt | ||
## output the relevant commits, and save to file | ||
echo "relevant commits:" | ||
for commit in "${logs[@]}"; do | ||
link="$(git log --format="[%h](https://github.com/pendulum-chain/pendulum/commit/%h) %s" -n 1 $commit)" | ||
echo $link | ||
echo -e "* "$link"\n" >> Commits.txt | ||
done | ||
|
||
$newVersionName | ||
echo "new version: "$tagNamePrefix"-"$versionNumber |