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
113 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,113 @@ | ||
name: Publish templates | ||
|
||
|
||
on: | ||
push: | ||
|
||
|
||
jobs: | ||
publish-templates: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: docker.io/paritytech/ci-unified:bullseye-1.75.0-2024-01-22-v20240109 | ||
strategy: | ||
matrix: | ||
template: ["minimal", "solochain", "parachain"] | ||
env: | ||
template-path: "polkadot-sdk-${{ matrix.template }}-template" | ||
polkadot-release-version: "1.9.0" | ||
steps: | ||
- 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 | ||
- 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 | ||
run: cargo install --git https://github.com/paritytech/psvm --rev a3ecef700e4c1429c2d01e265a145654ceb3cc49 psvm | ||
- name: Replace the workspace references in the template | ||
run: | | ||
set -euo pipefail | ||
# Use released creates, instead of git references. | ||
find . -type f -name 'Cargo.toml' -exec psvm -o -v ${{ env.polkadot-release-version }} -p {} \; | ||
# 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. | ||
# 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 | ||
echo "Result Cargo.toml debug" | ||
find . -type f -name 'Cargo.toml' -exec cat {} \; | ||
shell: bash | ||
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 }}/" | ||
- name: Check if it compiles | ||
id: check-compilation | ||
run: | | ||
set -e | ||
# Commented out for now. | ||
# cargo build | ||
cargo tree --depth 1 | ||
cargo fmt | ||
working-directory: "${{ env.template-path }}" | ||
- name: Push changes | ||
run: | | ||
git add -A . | ||
git commit --allow-empty -m "Pushed event" | ||
git push | ||
working-directory: "${{ env.template-path }}" |