|
| 1 | +name: Setup Workshop from Config |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'workshop_config.json' |
| 7 | + |
| 8 | +jobs: |
| 9 | + replace-variables: |
| 10 | + if: github.repository != 'cbw-dev/bookdown-template' |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout Repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + # --- CHANGE: This step now checks the config and sets an output --- |
| 20 | + - name: Load Variables and Check Config |
| 21 | + id: config |
| 22 | + run: | |
| 23 | + # Load all variables into the environment for later steps |
| 24 | + echo "WORKSHOP_CODE=$(jq -r .workshop_code workshop_config.json)" >> $GITHUB_ENV |
| 25 | + echo "WORKSHOP_NAME=$(jq -r .workshop_name workshop_config.json)" >> $GITHUB_ENV |
| 26 | + echo "YEAR=$(jq -r .year workshop_config.json)" >> $GITHUB_ENV |
| 27 | + echo "URL=$(jq -r .url workshop_config.json)" >> $GITHUB_ENV |
| 28 | + echo "DATES=$(jq -r .dates workshop_config.json)" >> $GITHUB_ENV |
| 29 | + echo "FACULTY=$(jq -r .faculty workshop_config.json)" >> $GITHUB_ENV |
| 30 | +
|
| 31 | + # Check the key variable and set a true/false output for the next steps |
| 32 | + if [[ "$(jq -r .workshop_code workshop_config.json)" == "Workshop Code (e.g. INR_Mon-2510)" ]]; then |
| 33 | + echo "is_configured=false" >> $GITHUB_OUTPUT |
| 34 | + echo "Configuration not complete. Halting." |
| 35 | + else |
| 36 | + echo "is_configured=true" >> $GITHUB_OUTPUT |
| 37 | + echo "Configuration complete. Proceeding with setup." |
| 38 | + fi |
| 39 | +
|
| 40 | + # --- CHANGE: All subsequent steps now check the output of the 'config' step --- |
| 41 | + - name: Rename .Rproj file |
| 42 | + if: steps.config.outputs.is_configured == 'true' |
| 43 | + run: mv template.Rproj "${{ env.WORKSHOP_CODE }}.Rproj" |
| 44 | + |
| 45 | + - name: Replace All Placeholders |
| 46 | + if: steps.config.outputs.is_configured == 'true' |
| 47 | + run: | |
| 48 | + find . -type f -not -path './.git/*' -not -path './.github/*' -exec sed -i \ |
| 49 | + -e "s|{{WORKSHOP_CODE}}|${WORKSHOP_CODE}|g" \ |
| 50 | + -e "s|{{WORKSHOP_NAME}}|${WORKSHOP_NAME}|g" \ |
| 51 | + -e "s|{{YEAR}}|${YEAR}|g" \ |
| 52 | + -e "s|{{URL}}|${URL}|g" \ |
| 53 | + -e "s|{{DATES}}|${DATES}|g" \ |
| 54 | + -e "s|{{FACULTY}}|${FACULTY}|g" \ |
| 55 | + {} + |
| 56 | +
|
| 57 | + - name: Clean up config file |
| 58 | + if: steps.config.outputs.is_configured == 'true' |
| 59 | + run: rm workshop_config.json |
| 60 | + |
| 61 | + - name: Commit and Push Changes |
| 62 | + if: steps.config.outputs.is_configured == 'true' |
| 63 | + run: | |
| 64 | + git config --global user.name 'github-actions[bot]' |
| 65 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 66 | + git add . |
| 67 | + git commit --amend -m "feat: setup workshop with custom variables" |
| 68 | + git push --force |
0 commit comments