Demo generate on schedule #145
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
# Your repository won't have this file | |
# secrets.PAT_CODE_WORKFLOWS | |
name: Demo generate | |
run-name: Demo generate on ${{ github.event_name }} | |
on: | |
schedule: | |
# Runs at 00:00 UTC | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
generate: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
type: [bin, lib] | |
flags: [yes-use-all, not-use-all, default-use] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_CODE_WORKFLOWS }} | |
- uses: dtolnay/rust-toolchain@stable | |
- name: Prexec | |
run: | | |
########## script ########## | |
rm -rf src/* || : | |
rm -rf Cargo.* || : | |
tags="${{ matrix.type }}-${{ matrix.flags }}" | |
default_branch="bin-yes-use-all" | |
echo "TAGS=${tags}" | tee -a "$GITHUB_ENV" | |
echo "DEFAULT_BRANCH=${default_branch}" | tee -a "$GITHUB_ENV" | |
# cleanup demo_* | |
[[ "$tags" != "$default_branch" ]] && { | |
rm .github/workflows/demo_* || : | |
} | |
#--silent | |
generate_cmd="cargo generate -o --init --git https://github.com/uplau/rust-template ./template --name 'rust-template-demo-${tags}' --${{ matrix.type }}" | |
generate_define="--define owner=uplau" | |
generate_define+=" --define copyright-year=2023" | |
default_use_badge="true" | |
default_use_contrib_rocks="false" | |
default_use_deps="true" | |
default_use_rust_template="true" | |
case "${{ matrix.flags }}" in | |
*'not-use-all') | |
default_use_badge="false" | |
default_use_deps="false" | |
default_use_rust_template="false" | |
;; | |
*'yes-use-all') | |
default_use_contrib_rocks="true" | |
;; | |
esac | |
generate_define+=" --define use-badge=$default_use_badge" | |
generate_define+=" --define use-contrib-rocks=$default_use_contrib_rocks" | |
generate_define+=" --define use-deps=$default_use_deps" | |
generate_define+=" --define use-rust-template=$default_use_rust_template" | |
echo "GENERATE_CMD=${generate_cmd}" | tee -a "$GITHUB_ENV" | |
echo "GENERATE_DEFINE=${generate_define}" | tee -a "$GITHUB_ENV" | |
- name: Install cargo-generate | |
uses: baptiste0928/cargo-install@v2 | |
with: | |
crate: cargo-generate | |
features: vendored-openssl | |
- name: Generate template | |
run: | | |
########## script ########## | |
eval $GENERATE_CMD $GENERATE_DEFINE | |
# fix all status badge | |
sed -i "s#uplau/rust-template-demo-${TAGS}#uplau/rust-template-demo#g" README.md | |
# fix main README | |
[[ "$TAGS" == "$DEFAULT_BRANCH" ]] && { | |
prefix_repo="https://github.com/uplau/rust-template-demo/tree" | |
type_flags=("bin-not-use-all" "bin-default-use" "lib-yes-use-all" "lib-not-use-all" "lib-default-use") | |
for tf in "${type_flags[@]}"; do | |
views+="- [View](${prefix_repo}/${tf}) \`${tf}\`\n" | |
done | |
views+="\n" | |
search="## Table of contents" | |
fmt_readme="This repository is automatically updated daily.\n\n> I am \`${DEFAULT_BRANCH}\`\n\n${views}${search}" | |
sed -i "s~${search}~${fmt_readme}~1" README.md | |
} | |
tree | |
- name: Update template | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git add . | |
git commit -m "chore: automatic update $TAGS" -m "[skip ci]" || : | |
if [[ "$TAGS" == "$DEFAULT_BRANCH" ]]; then | |
git push --force-with-lease origin | |
else | |
git tag -f "$TAGS" | |
git push -f origin "$TAGS" | |
fi | |
: |