Synchronize the example with the template #931
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
name: Synchronize the example with the template | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
# Runs at 00:00 UTC everyday | |
- cron: "0 0 * * *" | |
jobs: | |
synchronize_example: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
rust: [stable] | |
job: | |
- crate_type: "bin" | |
- crate_type: "lib" | |
env: | |
PROJECT_NAME: rust-template-generated-${{ matrix.job.crate_type }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: taiki-e/install-action@v2 | |
with: | |
tool: cargo-udeps,cargo-sync-rdme,cargo-generate | |
- run: rustup toolchain add nightly --profile minimal | |
shell: bash | |
- run: cargo generate --name "${{ env.PROJECT_NAME }}" --path "template" --template-values-file tests/template_values.toml --${{matrix.job.crate_type}} --allow-commands | |
shell: bash | |
- name: Run cargo generate-lockfile | |
run: | | |
cd "${PROJECT_NAME}" | |
cargo generate-lockfile | |
- name: Set env vars for bin | |
run: | | |
{ | |
echo 'SSH_KEY<<EOF' | |
echo "${{ secrets.GH_EXAMPLE_DEPLOY_BIN_SECRET }}" | |
echo 'EOF' | |
} >> "${GITHUB_ENV}" | |
if: ${{ matrix.job.crate_type == 'bin' }} | |
- name: Set env vars for lib | |
run: | | |
{ | |
echo 'SSH_KEY<<EOF' | |
echo "${{ secrets.GH_EXAMPLE_DEPLOY_LIB_SECRET }}" | |
} >> "${GITHUB_ENV}" | |
echo 'EOF' >> "${GITHUB_ENV}" | |
if: ${{ matrix.job.crate_type == 'lib' }} | |
- name: Checkout example repo | |
uses: actions/checkout@v4 | |
with: | |
repository: gifnksm/${{ env.PROJECT_NAME }} | |
path: example_repo | |
ssh-key: ${{ env.SSH_KEY }} | |
- name: update example | |
run: | | |
./tests/scripts/update_repo example_repo ${{ env.PROJECT_NAME }} | |
git -C example_repo add -N . | |
- name: test example | |
run: (cd example_repo && ../tests/scripts/run_cargo_tests "${{ matrix.job.crate_type }}") | |
- name: Check workflow files | |
run: | | |
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) | |
echo "::add-matcher::.github/actionlint-matcher.json" | |
(cd example_repo && ../actionlint -color) | |
shell: bash | |
- name: show example diff | |
run: git -C example_repo diff || true | |
- name: commit example | |
run: | | |
cd example_repo | |
git config user.name github-actions | |
git config user.email github-actions@example.com | |
git add . | |
if [ -n "$(git status --porcelain)" ]; then | |
git commit -m "automatic update" -m "from $GITHUB_REPOSITORY@$GITHUB_SHA" | |
git push | |
else | |
echo "nothing to commit"; | |
fi | |
if: ${{ startsWith(github.ref, 'refs/heads/main') }} |