|
| 1 | +name: Release Plugins |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - '**/plugindefinition.yaml' |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + detect-changes: |
| 15 | + runs-on: [ ubuntu-latest ] |
| 16 | + outputs: |
| 17 | + changed-plugins: ${{ steps.build-matrix.outputs.plugins }} |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 2 |
| 23 | + |
| 24 | + - name: Install 'yq' |
| 25 | + uses: yokawasa/action-setup-kube-tools@v0.11.2 |
| 26 | + with: |
| 27 | + yq: v4.25.1 |
| 28 | + setup-tools: | |
| 29 | + yq |
| 30 | +
|
| 31 | + - name: Prepare change detection |
| 32 | + id: prepare-filters |
| 33 | + run: | |
| 34 | + # Find all plugin directories with plugindefinition.yaml |
| 35 | + PLUGINS=$(find . -name 'plugindefinition.yaml' -not -path '*/\.*' | sed 's|/plugindefinition.yaml||' | sed 's|^\./||') |
| 36 | + |
| 37 | + # Create filter.yml for dorny/paths-filter |
| 38 | + yq e -n '.root = "."' > filter.yml |
| 39 | + echo "$PLUGINS" | while read plugin; do |
| 40 | + yq e -i ".$plugin = \"$plugin/plugindefinition.yaml\"" filter.yml |
| 41 | + done |
| 42 | + yq e -i 'del(.root)' filter.yml |
| 43 | + cat filter.yml |
| 44 | +
|
| 45 | + - name: Detect changed plugins |
| 46 | + uses: dorny/paths-filter@v3 |
| 47 | + id: filter |
| 48 | + with: |
| 49 | + filters: ./filter.yml |
| 50 | + |
| 51 | + - name: Build plugin matrix |
| 52 | + id: build-matrix |
| 53 | + run: | |
| 54 | + CHANGED_PLUGINS='${{ steps.filter.outputs.changes }}' |
| 55 | + |
| 56 | + if [ "$CHANGED_PLUGINS" = "[]" ]; then |
| 57 | + echo "No plugins changed" |
| 58 | + echo "plugins=[]" >> $GITHUB_OUTPUT |
| 59 | + exit 0 |
| 60 | + fi |
| 61 | + |
| 62 | + # Build JSON array with plugin metadata |
| 63 | + PLUGINS="[]" |
| 64 | + for plugin in $(echo "$CHANGED_PLUGINS" | jq -c -r '.[]'); do |
| 65 | + if [ -f "$plugin/plugindefinition.yaml" ]; then |
| 66 | + PLUGIN_NAME=$(yq e '.metadata.name' "$plugin/plugindefinition.yaml") |
| 67 | + PLUGIN_VERSION=$(yq e '.spec.version' "$plugin/plugindefinition.yaml") |
| 68 | + |
| 69 | + PLUGINS=$(echo "$PLUGINS" | jq -c ". += [{\"name\": \"$PLUGIN_NAME\", \"version\": \"$PLUGIN_VERSION\", \"dir\": \"$plugin\"}]") |
| 70 | + fi |
| 71 | + done |
| 72 | + |
| 73 | + echo "plugins=$PLUGINS" >> $GITHUB_OUTPUT |
| 74 | + echo "Changed plugins: $PLUGINS" |
| 75 | +
|
| 76 | + release: |
| 77 | + if: needs.detect-changes.outputs.changed-plugins != '[]' |
| 78 | + runs-on: [self-hosted] |
| 79 | + needs: [detect-changes] |
| 80 | + name: Release Plugin ${{ matrix.plugin.name }} |
| 81 | + strategy: |
| 82 | + fail-fast: false |
| 83 | + matrix: |
| 84 | + plugin: ${{ fromJson(needs.detect-changes.outputs.changed-plugins) }} |
| 85 | + steps: |
| 86 | + - name: Checkout repository |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Release (${{ matrix.plugin.name }}) |
| 90 | + uses: actions/github-script@v7 |
| 91 | + with: |
| 92 | + script: | |
| 93 | + const pluginName = '${{ matrix.plugin.name }}'; |
| 94 | + const pluginVersion = '${{ matrix.plugin.version }}'; |
| 95 | + const tagName = `${pluginName}/${pluginVersion}`; |
| 96 | + |
| 97 | + console.log(`Creating tag ${tagName}`); |
| 98 | + |
| 99 | + try { |
| 100 | + await github.rest.git.createRef({ |
| 101 | + owner: context.repo.owner, |
| 102 | + repo: context.repo.repo, |
| 103 | + ref: `refs/tags/${tagName}`, |
| 104 | + sha: context.sha |
| 105 | + }); |
| 106 | + console.log(`Successfully created tag ${tagName}`); |
| 107 | + } catch (error) { |
| 108 | + if (error.status === 422 && error.message.includes('already exists')) { |
| 109 | + console.log(`Tag ${tagName} already exists, skipping...`); |
| 110 | + } else { |
| 111 | + throw error; |
| 112 | + } |
| 113 | + } |
0 commit comments