|
| 1 | +name: GitHub Release Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + ## Pepararation job for setting up relevant variables |
| 9 | + setup: |
| 10 | + name: Setup variables |
| 11 | + runs-on: ubuntu-latest |
| 12 | + # Declare output variables to be usable in other jobs |
| 13 | + outputs: |
| 14 | + output1: ${{steps.var_step.outputs.version}} |
| 15 | + output2: ${{steps.date_step.outputs.docdate}} |
| 16 | + output3: ${{steps.var_step.outputs.suffix}} |
| 17 | + steps: |
| 18 | + # Check out the GitHub repository |
| 19 | + - name: Checkout interface |
| 20 | + uses: actions/checkout@v3 |
| 21 | + with: |
| 22 | + path: dist/open-simulation-interface |
| 23 | + # Set the version variable based on the latest tag (could be replaced with github-internal predefined variable?) |
| 24 | + - name: Set version |
| 25 | + id: var_step |
| 26 | + working-directory: dist/open-simulation-interface |
| 27 | + run: | |
| 28 | + echo "version=$(git describe --tags --always | sed 's/^v//')" >> $GITHUB_OUTPUT |
| 29 | + echo "suffix=$(git describe --tags --always | sed -r 's/^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+//')" >> $GITHUB_OUTPUT |
| 30 | + # Set the release date (current date) |
| 31 | + - name: Set date |
| 32 | + id: date_step |
| 33 | + run: echo "docdate=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT |
| 34 | + |
| 35 | + ## Tag and update related repositories before checking them out for Antora and the deliverables |
| 36 | + tagging_update: |
| 37 | + name: Update OSMP & Documentation |
| 38 | + runs-on: ubuntu-22.04 |
| 39 | + needs: [setup] |
| 40 | + steps: |
| 41 | + - name: Update OSMP |
| 42 | + uses: peter-evans/repository-dispatch@v2 |
| 43 | + with: |
| 44 | + token: ${{ secrets.MACHINE_USER_PAT }} |
| 45 | + event-type: update-tag |
| 46 | + repository: OpenSimulationInterface/osi-sensor-model-packaging |
| 47 | + client-payload: '{"tag": "v${{needs.setup.outputs.output1}}", "suffix": "${{needs.setup.outputs.output3}}", "source_repo": "${{ github.repository }}"}' |
| 48 | + - name: Update Documentation |
| 49 | + uses: peter-evans/repository-dispatch@v2 |
| 50 | + with: |
| 51 | + token: ${{ secrets.MACHINE_USER_PAT }} |
| 52 | + event-type: update-tag |
| 53 | + repository: OpenSimulationInterface/osi-documentation |
| 54 | + client-payload: '{"tag": "v${{needs.setup.outputs.output1}}"}' |
| 55 | + - name: Provide downstream repos some time |
| 56 | + uses: whatnick/wait-action@v0.1.2 |
| 57 | + with: |
| 58 | + time: '1m' |
| 59 | + |
| 60 | + |
| 61 | + ## Antora job, responsible for creating the Antora output of the release |
| 62 | + antora: |
| 63 | + name: Generate Antora content |
| 64 | + runs-on: ubuntu-22.04 |
| 65 | + needs: [tagging_update] |
| 66 | + steps: |
| 67 | + # Check out the Antora generator |
| 68 | + - name: Checkout Antora generator |
| 69 | + uses: actions/checkout@v3 |
| 70 | + with: |
| 71 | + repository: OpenSimulationInterface/osi-antora-generator |
| 72 | + path: antora |
| 73 | + submodules: true |
| 74 | + # Remove building branches for the main repositories. This will lead to Antora only using the tagged versions to build its content. |
| 75 | + - name: Manipulate site.yml |
| 76 | + working-directory: antora |
| 77 | + run: | |
| 78 | + sed -i -E 's/branches: (.*) \# (open-.*|osi-.*)/branches: ~/g' site.yml |
| 79 | + cat site.yml |
| 80 | + # Create custom build instructions for GitHub compatibility |
| 81 | + - name: Create run instructions |
| 82 | + run: | |
| 83 | + echo "#!/bin/bash |
| 84 | + cd antora |
| 85 | + cat site.yml |
| 86 | + export NODE_OPTIONS="--max-old-space-size=8192" |
| 87 | + exec antora --stacktrace --fetch --clean site.yml" > antora.sh |
| 88 | + cat antora.sh |
| 89 | + # Run Antora to generate the document |
| 90 | + - name: Run Antora |
| 91 | + uses: docker://ghcr.io/asam-ev/project-guide-docker:4 |
| 92 | + with: |
| 93 | + entrypoint: sh |
| 94 | + args: antora.sh |
| 95 | + # Upload the created artifact for later jobs to use |
| 96 | + - name: Upload artifact |
| 97 | + uses: actions/upload-artifact@v3 |
| 98 | + with: |
| 99 | + name: antora |
| 100 | + path: antora/site |
| 101 | + |
| 102 | + ## Step for creating the zip file with all deliverables |
| 103 | + deliverables: |
| 104 | + name: Create deliverables package |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: [setup,antora] |
| 107 | + steps: |
| 108 | + # Check out the repository (again) |
| 109 | + - name: Checkout interface |
| 110 | + uses: actions/checkout@v3 |
| 111 | + with: |
| 112 | + path: dist/open-simulation-interface |
| 113 | + # Check out the sensor model packaging repo |
| 114 | + - name: Checkout sensor model packaging |
| 115 | + uses: actions/checkout@v3 |
| 116 | + with: |
| 117 | + repository: OpenSimulationInterface/osi-sensor-model-packaging |
| 118 | + path: dist/osi-sensor-model-packaging |
| 119 | + fetch-depth: 0 |
| 120 | + # Retrieve the Antora artifact from the previous job |
| 121 | + - name: Retrieve Antora artifact |
| 122 | + uses: actions/download-artifact@v3 |
| 123 | + with: |
| 124 | + name: antora |
| 125 | + path: dist/ASAM_OSI_Standard_${{needs.setup.outputs.output1}}/ |
| 126 | +# # Move downloaded Antora artifact to the correct location |
| 127 | +# - name: Move and rename Antora artifact (ASAM_OSI_Standard) |
| 128 | +# run: | |
| 129 | +# ls |
| 130 | +# mv antora/site/ dist/ASAM_OSI_Standard_${{needs.setup.outputs.output1}}/ |
| 131 | + # Create the mandatory README.txt file for the deliverables package. The functions and variables declared below will create a readme file with a defined header, surrounded by a box made of "*". |
| 132 | + - name: Get OSMP version |
| 133 | + working-directory: dist/osi-sensor-model-packaging |
| 134 | + run: | |
| 135 | + OSMP_VERSION="$(git describe --tags --exclude 'v*.*.*-antora' --exclude 'x-antora-v*.*.*'| sed 's/^v//')" |
| 136 | + echo "OSMP_VERSION=$OSMP_VERSION" >> $GITHUB_ENV |
| 137 | + - name: Create README |
| 138 | + working-directory: dist |
| 139 | + run: | |
| 140 | + declare -i char_count=84 |
| 141 | + declare -i char_count_header=$char_count-1 |
| 142 | + repeat(){ for i in $(eval echo {1..$1}); do echo -n "$2"; done; echo ""; } |
| 143 | + fill(){ declare -i length=$1-${#2}-9; spaces=$(repeat $length ".");echo "***" "$2" "${spaces//./ }" "***"; } |
| 144 | + name="ASAM OSI" |
| 145 | + version="Version: ${{needs.setup.outputs.output1}}" |
| 146 | + date="Date: ${{needs.setup.outputs.output2}}" |
| 147 | + |
| 148 | + echo "/$(repeat $char_count_header "*")" > README.txt |
| 149 | + fill $char_count "$name" >> README.txt |
| 150 | + fill $char_count "$version" >> README.txt |
| 151 | + fill $char_count "$date" >> README.txt |
| 152 | + echo "$(repeat $char_count_header "*")/" >> README.txt |
| 153 | + echo "The deliverables of ASAM OSI v${{needs.setup.outputs.output1}} include: |
| 154 | +
|
| 155 | + - ASAM_OSI_Standard_${{needs.setup.outputs.output1}} |
| 156 | + - open_simulation_interface_${{needs.setup.outputs.output1}} |
| 157 | + - osi-sensor-model-packaging_${{ env.OSMP_VERSION }}" >> "README.txt" |
| 158 | + cat README.txt |
| 159 | + # Package all collected deliverables |
| 160 | + - name: Zip Release |
| 161 | + uses: TheDoctor0/zip-release@0.6.2 |
| 162 | + with: |
| 163 | + filename: ASAM_OSI_${{needs.setup.outputs.output1}}.zip |
| 164 | + directory: dist |
| 165 | + # Upload the created artifact for the publish job |
| 166 | + - name: Upload artifact |
| 167 | + uses: actions/upload-artifact@v3 |
| 168 | + with: |
| 169 | + name: deliverables |
| 170 | + path: dist/ASAM_OSI_${{needs.setup.outputs.output1}}.zip |
| 171 | + |
| 172 | + ## Publishing step, where the created zip file is uploaded to the triggering release publication |
| 173 | + publish: |
| 174 | + name: Add deliverables to release |
| 175 | + runs-on: ubuntu-latest |
| 176 | + needs: [deliverables, setup] |
| 177 | + steps: |
| 178 | + # Retrieve the previously uploaded deliverables artifact |
| 179 | + - name: Retrieve previous artifacts |
| 180 | + uses: actions/download-artifact@v3 |
| 181 | + with: |
| 182 | + name: deliverables |
| 183 | + # Add the new zip file with the deliverables to the respective release |
| 184 | + - name: Add deliverables to release |
| 185 | + uses: svenstaro/upload-release-action@v2 |
| 186 | + with: |
| 187 | + file: ASAM_OSI_${{needs.setup.outputs.output1}}.zip |
| 188 | + tag: ${{ github.ref }} |
0 commit comments