|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: remove_solution |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + # Triggers the workflow on push or pull request events but only for the "main" branch |
| 8 | + push: |
| 9 | + branches: [ "with_solution" ] |
| 10 | + |
| 11 | + # Allows you to run this workflow manually from the Actions tab |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + TARGET_BRANCH: main |
| 16 | + SOURCE_BRANCH: with_solution |
| 17 | + FILE1_PRE: 1_ViennaRNA_Introduction.ipynb |
| 18 | + FILE1_POST: 1_ViennaRNA_Introduction_No_Solution.ipynb |
| 19 | + FILE2_PRE: 2_Practical_Example.ipynb |
| 20 | + FILE2_POST: 2_Practical_Example_No_Solution.ipynb |
| 21 | + OTHER_FILES: README.md 2_input .github/workflows |
| 22 | + |
| 23 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 24 | +jobs: |
| 25 | + # This workflow contains a single job called "build" |
| 26 | + remove_solution_and_sync: |
| 27 | + # The type of runner that the job will run on |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 31 | + steps: |
| 32 | + |
| 33 | + # Runs a single command using the runners shell |
| 34 | + - uses: actions/checkout@v2 |
| 35 | + - name: Create a new file without solutions |
| 36 | + run: | |
| 37 | + git config --global user.name 'GitHub Action' |
| 38 | + git config --global user.email 'action@github.com' |
| 39 | + git fetch |
| 40 | + git checkout $SOURCE_BRANCH |
| 41 | + jq --arg kw "solution" '.cells |= map(select((.metadata | tostring | contains($kw)) | not))' $FILE1_PRE > ${FILE1_POST}_tmp |
| 42 | + jq --arg kw "solution" '.cells |= map(select((.metadata | tostring | contains($kw)) | not))' $FILE2_PRE > ${FILE2_POST}_tmp |
| 43 | + for file in $OTHER_FILES; do |
| 44 | + cp -r $file ${file}_tmp |
| 45 | + done |
| 46 | +
|
| 47 | + # Runs a set of commands using the runners shell |
| 48 | + - name: Move it to target branch |
| 49 | + run: | |
| 50 | + git config --global user.name 'GitHub Action' |
| 51 | + git config --global user.email 'action@github.com' |
| 52 | + git fetch |
| 53 | + git checkout $TARGET_BRANCH |
| 54 | + mv ${FILE1_POST}_tmp ${FILE1_POST} |
| 55 | + mv ${FILE2_POST}_tmp ${FILE2_POST} |
| 56 | + for file in $OTHER_FILES; do |
| 57 | + rm -r ${file} |
| 58 | + mv ${file}_tmp ${file} |
| 59 | + done |
| 60 | + git add -A |
| 61 | + git diff-index --quiet HEAD || git commit -am "deploy files" |
| 62 | + git push origin $TARGET_BRANCH |
| 63 | +
|
| 64 | + |
0 commit comments