|
| 1 | +name: Publish opensips.org documentation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'examples/**' |
| 7 | + - 'modules/*/samples/**' |
| 8 | + - 'docs/manual/**' |
| 9 | + - 'net/*/README.md' |
| 10 | + - 'modules/*/README.md' |
| 11 | + |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: notify-web-${{ github.ref }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + changed-components: |
| 23 | + name: Find changed documentation components |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.components.outputs.matrix }} |
| 27 | + has-components: ${{ steps.components.outputs.has-components }} |
| 28 | + steps: |
| 29 | + - name: Check out the repository |
| 30 | + uses: actions/checkout@v5 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Detect changed components |
| 35 | + id: components |
| 36 | + shell: bash |
| 37 | + env: |
| 38 | + EVENT_NAME: ${{ github.event_name }} |
| 39 | + BEFORE: ${{ github.event.before }} |
| 40 | + SHA: ${{ github.sha }} |
| 41 | + run: | |
| 42 | + if [[ "$EVENT_NAME" != "push" ]]; then |
| 43 | + changed_files=$'examples/\ndocs/manual/\nmodules/all/README.md' |
| 44 | + elif [[ "$BEFORE" == "0000000000000000000000000000000000000000" ]]; then |
| 45 | + changed_files="$(git ls-tree -r --name-only "$SHA")" |
| 46 | + else |
| 47 | + changed_files="$(git diff --name-only "$BEFORE" "$SHA")" |
| 48 | + fi |
| 49 | +
|
| 50 | + components=() |
| 51 | + modules=() |
| 52 | + declare -A module_names=() |
| 53 | +
|
| 54 | + while IFS= read -r path; do |
| 55 | + [[ "$path" =~ ^examples/ || "$path" =~ ^modules/[^/]+/samples/ ]] && components+=(samples) |
| 56 | + [[ "$path" =~ ^docs/manual/ ]] && components+=(manual) |
| 57 | + if [[ "$path" =~ ^(net|modules)/([^/]+)/README\.md$ ]]; then |
| 58 | + module_names["${BASH_REMATCH[2]}"]=1 |
| 59 | + fi |
| 60 | + done <<< "$changed_files" |
| 61 | +
|
| 62 | + components=( $(printf '%s\n' "${components[@]}" | sort -u) ) |
| 63 | + for module in "${!module_names[@]}"; do |
| 64 | + modules+=("$module") |
| 65 | + done |
| 66 | + IFS=$'\n' read -r -d '' -a modules < <(printf '%s\n' "${modules[@]}" | sort && printf '\0') || true |
| 67 | +
|
| 68 | + if [[ ${#components[@]} -eq 0 && ${#modules[@]} -eq 0 ]]; then |
| 69 | + echo 'has-components=false' >> "$GITHUB_OUTPUT" |
| 70 | + echo 'matrix={"include":[]}' >> "$GITHUB_OUTPUT" |
| 71 | + exit 0 |
| 72 | + fi |
| 73 | +
|
| 74 | + components_json="$(printf '%s\n' "${components[@]}" | jq -R -s 'split("\n") | map(select(length > 0) | {component: .})')" |
| 75 | + modules_json="$(printf '%s\n' "${modules[@]}" | jq -R -s 'split("\n") | map(select(length > 0) | {component: "modules", module: .})')" |
| 76 | + matrix="$(jq -cn --argjson components "$components_json" --argjson modules "$modules_json" '{include: ($components + $modules)}')" |
| 77 | + echo "has-components=true" >> "$GITHUB_OUTPUT" |
| 78 | + echo "matrix=$matrix" >> "$GITHUB_OUTPUT" |
| 79 | +
|
| 80 | + dispatch: |
| 81 | + name: Trigger ${{ matrix.component }} publication |
| 82 | + needs: changed-components |
| 83 | + if: ${{ needs.changed-components.outputs.has-components == 'true' }} |
| 84 | + runs-on: ubuntu-latest |
| 85 | + strategy: |
| 86 | + fail-fast: false |
| 87 | + matrix: ${{ fromJSON(needs.changed-components.outputs.matrix) }} |
| 88 | + steps: |
| 89 | + - name: Create GitHub App token |
| 90 | + id: app-token |
| 91 | + uses: actions/create-github-app-token@v3 |
| 92 | + with: |
| 93 | + client-id: ${{ secrets.OPENSIPS_WEB_APP }} |
| 94 | + private-key: ${{ secrets.OPENSIPS_WEB_KEY }} |
| 95 | + owner: OpenSIPS |
| 96 | + repositories: ${{ secrets.OPENSIPS_WEB_REPO }} |
| 97 | + permission-actions: write |
| 98 | + |
| 99 | + - name: Trigger private publish workflow |
| 100 | + if: ${{ matrix.module == '' }} |
| 101 | + uses: step-security/workflow-dispatch@v1 |
| 102 | + with: |
| 103 | + token: ${{ steps.app-token.outputs.token }} |
| 104 | + repo: ${{ secrets.OPENSIPS_WEB_REPO }} |
| 105 | + workflow: publish.yml |
| 106 | + ref: main |
| 107 | + inputs: '{"component": "${{ matrix.component }}", "version": "${{ github.ref_name }}"}' |
| 108 | + |
| 109 | + - name: Trigger private module publication |
| 110 | + if: ${{ matrix.module != '' }} |
| 111 | + uses: step-security/workflow-dispatch@v1 |
| 112 | + with: |
| 113 | + token: ${{ steps.app-token.outputs.token }} |
| 114 | + repo: ${{ secrets.OPENSIPS_WEB_REPO }} |
| 115 | + workflow: publish.yml |
| 116 | + ref: main |
| 117 | + inputs: '{"component": "modules", "module": "${{ matrix.module }}", "version": "${{ github.ref_name }}"}' |
0 commit comments