forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
167 additions
and
0 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,167 @@ | ||
name: Publish templates | ||
|
||
|
||
# This job is used to keep the repository templates up-to-date. | ||
# The code of the templates exist inside the monorepo, and upon releases we synchronize the repositories: | ||
# - https://github.com/paritytech/polkadot-sdk-minimal-template | ||
# - https://github.com/paritytech/polkadot-sdk-parachain-template | ||
# - https://github.com/paritytech/polkadot-sdk-solochain-template | ||
# | ||
# The job moves the template code out of the monorepo, | ||
# replaces any references to the monorepo workspace using psvm and sed, | ||
# checks that it builds successfully, | ||
# and commits and pushes the result to each respective repository. | ||
# If the build fails, a PR is created instead for manual inspection. | ||
|
||
|
||
on: | ||
push: # For testing locally, to be removed. | ||
# A manual dispatch for now - automatic on releases later. | ||
workflow_dispatch: | ||
inputs: | ||
release_branch: | ||
description: 'A branch to use, e.g. release-crates-io-v1.x.x' | ||
required: true | ||
|
||
|
||
jobs: | ||
publish-templates: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: docker.io/paritytech/ci-unified:bullseye-1.75.0-2024-01-22-v20240109 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
template: ["minimal", "solochain", "parachain"] | ||
env: | ||
template-path: "polkadot-sdk-${{ matrix.template }}-template" | ||
polkadot-release-version: "1.9.0" | ||
steps: | ||
|
||
# 1. Prerequisites. | ||
|
||
- name: Configure git identity | ||
run: | | ||
git config --global user.name "Template Bot" | ||
git config --global user.email "163130811+polkadot-sdk-template-bot-stg[bot]@users.noreply.github.com" | ||
- uses: actions/checkout@v3 | ||
with: | ||
path: polkadot-sdk | ||
ref: "${{ github.event.inputs.release_branch }}" | ||
- name: Generate token | ||
id: app_token | ||
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 | ||
with: | ||
app_id: ${{ secrets.TEMPLATE_APP_ID }} | ||
private_key: ${{ secrets.TEMPLATE_APP_KEY }} | ||
- uses: actions/checkout@v3 | ||
with: | ||
repository: "paritytech-stg/polkadot-sdk-${{ matrix.template }}-template" | ||
path: "${{ env.template-path }}" | ||
token: ${{ steps.app_token.outputs.token }} | ||
- name: Install Polkadot SDK Version Manager | ||
# run: cargo install --git https://github.com/paritytech/psvm --rev ad7eb4333c124b0b7169359f1463ba40cd5d55dd psvm | ||
# https://github.com/paritytech/psvm/pull/7 | ||
run: cargo install --git https://github.com/paritytech/psvm --rev a3ecef700e4c1429c2d01e265a145654ceb3cc49 psvm | ||
|
||
# 2. Yanking the template out of the monorepo workspace. | ||
|
||
- name: Use psvm to replace git references with released creates. | ||
run: find . -type f -name 'Cargo.toml' -exec psvm -o -v ${{ env.polkadot-release-version }} -p {} \; | ||
working-directory: polkadot-sdk/templates/${{ matrix.template }}/ | ||
- name: Yank the template out of the workspace | ||
run: | | ||
set -euo pipefail | ||
# Set the Rust edition. | ||
rust_edition=$(cat ../../Cargo.toml | grep "edition =") | ||
find . -type f -name 'Cargo.toml' -exec sed -i -E "s/edition\.workspace = true\$/$rust_edition/g" {} \; | ||
# Get rid of "authors.workspace = true" and similar entries. | ||
find . -type f -name 'Cargo.toml' -exec sed -i -E "/^.*\.workspace = true\$/d" {} \; | ||
# Replace workspace dependencies with actual versions - it is not handled by psvm. | ||
# e.g. serde_json = { workspace = true, default-features = true } | ||
replace_workspace_deps () { | ||
# To preserve TAB identation. | ||
IFS='' | ||
echo "Replacing workspace deps in $1" | ||
while read line; do | ||
if echo "$line" | grep -q -E ".* = .* workspace = true" | ||
then | ||
pkg=$(echo $line | sed -E 's/(.*) = \{(.*)/\1/') | ||
echo "Replacing workspace dependency ${pkg}." | ||
cargo tree --depth 1 --prefix none | grep "${pkg} v" | ||
version=$(cargo tree --depth 1 --prefix none | grep "${pkg} v" | head -1 | sed -E "s/${pkg} v//" | tr -d '\n') | ||
echo "Version: $version" | ||
line=$(echo "$line" | sed -E "s/workspace = true/version = \"${version}\"/") | ||
fi | ||
echo "$line" >> "${1}.temp" | ||
done < "$1" | ||
mv "${1}.temp" "$1" | ||
} | ||
export -f replace_workspace_deps | ||
find . -type f -name 'Cargo.toml' -exec bash -c 'replace_workspace_deps {}' \; | ||
# Get rid of "workspace = true" and create a new workspace. | ||
find . -type f -name 'Cargo.toml' -exec sed -i -E "/^workspace = true\$/d" {} \; | ||
cat << EOF > Cargo.toml | ||
[workspace] | ||
members = [ | ||
"node", | ||
"pallets/template", | ||
"runtime", | ||
] | ||
resolver = "2" | ||
EOF | ||
shell: bash | ||
working-directory: polkadot-sdk/templates/${{ matrix.template }}/ | ||
- name: Print the result Cargo.tomls for debugging | ||
if: runner.debug == '1' | ||
run: find . -type f -name 'Cargo.toml' -exec cat {} \; | ||
working-directory: polkadot-sdk/templates/${{ matrix.template }}/ | ||
|
||
- name: Clean the destination repository | ||
run: rm -rf ./* | ||
working-directory: "${{ env.template-path }}" | ||
- name: Copy over the new changes | ||
run: | | ||
cp -r polkadot-sdk/templates/${{ matrix.template }}/* "${{ env.template-path }}/" | ||
# The new repository does not have lint settings specific to polkadot-sdk. | ||
# We reformat it without those settings. | ||
- name: Reformat the repository | ||
run: cargo fmt | ||
working-directory: "${{ env.template-path }}" | ||
|
||
# 3. Verify the build. Push the changes or create a PR. | ||
|
||
- name: Check if it compiles | ||
id: check-compilation | ||
run: | | ||
set -e | ||
# Uncomment later. | ||
# cargo build | ||
# cargo test | ||
# Run anything instead, to generate Cargo.lock | ||
cargo tree --depth 1 | ||
working-directory: "${{ env.template-path }}" | ||
timeout-minutes: 90 | ||
- name: Create PR on failure | ||
if: failure() && steps.check-compilation.outcome == 'failure' | ||
uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5 # v5 | ||
with: | ||
path: "${{ env.template-path }}" | ||
token: ${{ steps.app_token.outputs.token }} | ||
add-paths: | | ||
./* | ||
title: "[Don't merge] Update the ${{ matrix.template }} template" | ||
body: "The template has NOT been successfully built and needs to be inspected." | ||
branch: "update-template/${{ github.event_name }}" | ||
- name: Push changes | ||
run: | | ||
git add -A . | ||
git commit --allow-empty -m "Pushed event" | ||
git push | ||
working-directory: "${{ env.template-path }}" |