|
| 1 | +name: Build and Publish Rocks |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + prepare: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + ghcr-upload: ${{ steps.read-ci-config.outputs.ghcr-upload }} |
| 15 | + build-matrix: ${{ steps.read-ci-config.outputs.build-matrix }} |
| 16 | + upload-matrix: ${{ steps.read-ci-config.outputs.upload-matrix }} |
| 17 | + arch-map: ${{ steps.set-map.outputs.arch-map }} |
| 18 | + steps: |
| 19 | + - name: Checkout Repository |
| 20 | + uses: actions/checkout@v5 |
| 21 | + |
| 22 | + - name: Read .github/ci.yaml |
| 23 | + id: read-ci-config |
| 24 | + uses: canonical/rocks-template-actions/actions/read-ci-config@v1 |
| 25 | + |
| 26 | + - name: Set Architecture Map |
| 27 | + id: set-map |
| 28 | + run: | |
| 29 | + if [[ "${{ github.repository_owner }}" != "canonical" ]]; then |
| 30 | + echo 'arch-map={"amd64":["ubuntu-24.04"],"arm64":["ubuntu-24.04-arm"]}' >> $GITHUB_OUTPUT |
| 31 | + fi |
| 32 | +
|
| 33 | + # TODO: remove once the pro-feature is stable in rockcraft |
| 34 | + # Warn the user if using tests in a pro enabled build |
| 35 | + - name: Check Pro and Test Incompatibility |
| 36 | + run: | |
| 37 | + build_matrix='${{ steps.read-ci-config.outputs.build-matrix }}' |
| 38 | +
|
| 39 | + # Use jq to iterate over the 'include' array |
| 40 | + echo "$build_matrix" | jq -c '.include[]' | while read -r row; do |
| 41 | + directory=$(echo "$row" | jq -r '.["directory"] // "unknown"') |
| 42 | + pro_services=$(echo "$row" | jq -r '.["pro-services"] // ""') |
| 43 | + run_tests=$(echo "$row" | jq -r '.["run-tests"] // "false"') |
| 44 | +
|
| 45 | + if [[ -n "$pro_services" && "$run_tests" == "true" ]]; then |
| 46 | + echo "::warning::Tests for Pro Services are currently not supported. Rockcraft tests will be skipped for ${directory}." |
| 47 | + fi |
| 48 | + done |
| 49 | +
|
| 50 | +
|
| 51 | + build: |
| 52 | + needs: [prepare] |
| 53 | + strategy: |
| 54 | + matrix: ${{ fromJSON(needs.prepare.outputs.build-matrix) }} |
| 55 | + uses: canonical/oci-factory/.github/workflows/Build-Rock.yaml@main |
| 56 | + with: |
| 57 | + rock-repo: ${{ github.event.pull_request.head.repo.full_name || github.repository }} |
| 58 | + rock-repo-commit: ${{ github.head_ref || github.ref_name }} |
| 59 | + rockfile-directory: ${{ matrix.directory }} |
| 60 | + oci-archive-name: ${{ matrix.artifact-name }} |
| 61 | + arch-map: ${{ needs.prepare.outputs.arch-map }} |
| 62 | + rockcraft-test: ${{ matrix.run-tests }} |
| 63 | + pro-services: ${{ matrix.pro-services }} |
| 64 | + secrets: |
| 65 | + source-github-token: ${{ secrets.REPO_CLONER_TOKEN }} |
| 66 | + pro-token: ${{ secrets[matrix.pro-token] }} |
| 67 | + pro-artifact-passphrase: ${{ secrets[matrix.pro-artifact-passphrase] }} |
| 68 | + |
| 69 | + |
| 70 | + test: |
| 71 | + needs: [prepare, build] |
| 72 | + strategy: |
| 73 | + fail-fast: false |
| 74 | + matrix: ${{ fromJSON(needs.prepare.outputs.build-matrix) }} |
| 75 | + uses: canonical/oci-factory/.github/workflows/Test-Rock.yaml@main |
| 76 | + with: |
| 77 | + oci-archive-name: ${{ matrix.artifact-name }} |
| 78 | + secrets: |
| 79 | + pro-artifact-passphrase: ${{ secrets[matrix.pro-artifact-passphrase] }} |
| 80 | + |
| 81 | + |
| 82 | + upload-ghcr: |
| 83 | + needs: [prepare, test] |
| 84 | + runs-on: ubuntu-latest |
| 85 | + if: | |
| 86 | + needs.prepare.outputs.ghcr-upload == 'true' && |
| 87 | + github.event_name != 'pull_request' && |
| 88 | + github.ref == 'refs/heads/main' |
| 89 | + strategy: |
| 90 | + matrix: ${{ fromJSON(needs.prepare.outputs.build-matrix) }} |
| 91 | + fail-fast: false |
| 92 | + permissions: |
| 93 | + packages: write |
| 94 | + steps: |
| 95 | + - name: Pre-Check Pro Enabled Rocks |
| 96 | + if: ${{ github.event.repository.visibility == 'public' && matrix.pro-services != '' }} |
| 97 | + run: | |
| 98 | + echo "::warning::Uploading Pro enabled rocks to GHCR is not allowed for public repositories." |
| 99 | + |
| 100 | + - name: Upload Rock to GHCR |
| 101 | + if: ${{ github.event.repository.visibility != 'public' || matrix.pro-services == '' }} |
| 102 | + uses: canonical/oci-factory/.github/actions/upload-rock@main |
| 103 | + with: |
| 104 | + artifact_name: ${{ matrix.artifact-name }} |
| 105 | + tags: ${{ matrix.tag }} |
| 106 | + name: ${{ matrix.name }} |
| 107 | + registry: ghcr.io/${{ github.repository }} |
| 108 | + username: ${{ github.actor }} |
| 109 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + decrypt-passphrase: ${{ secrets[matrix.pro-artifact-passphrase] }} |
| 111 | + |
| 112 | + |
| 113 | + upload-registries: |
| 114 | + needs: [prepare, test] |
| 115 | + runs-on: ubuntu-latest |
| 116 | + if: | |
| 117 | + needs.prepare.outputs.upload-matrix != '{"include": []}' && |
| 118 | + github.event_name != 'pull_request' && |
| 119 | + github.ref == 'refs/heads/main' |
| 120 | + strategy: |
| 121 | + matrix: ${{ fromJSON(needs.prepare.outputs.upload-matrix) }} |
| 122 | + fail-fast: false |
| 123 | + steps: |
| 124 | + - name: Prepare ECR Session Token |
| 125 | + if: ${{ contains(matrix.registry-auth-method, 'ecr') }} |
| 126 | + id: get-ecr-token |
| 127 | + env: |
| 128 | + AWS_ACCESS_KEY_ID: ${{ secrets[matrix.registry-auth-username] }} |
| 129 | + AWS_SECRET_ACCESS_KEY: ${{ secrets[matrix.registry-auth-password] }} |
| 130 | + run: | |
| 131 | + session_token=$(aws ${{ matrix.registry-auth-method }} \ |
| 132 | + get-login-password \ |
| 133 | + --region ${{ matrix.registry-auth-region }} \ |
| 134 | + ) |
| 135 | + echo "::add-mask::$session_token" |
| 136 | + echo "aws-session-token=$session_token" >> $GITHUB_OUTPUT |
| 137 | +
|
| 138 | + - name: Upload Rock to ECR |
| 139 | + uses: canonical/oci-factory/.github/actions/upload-rock@main |
| 140 | + if: ${{ contains(matrix.registry-auth-method, 'ecr') }} |
| 141 | + with: |
| 142 | + artifact_name: ${{ matrix.artifact-name }} |
| 143 | + tags: ${{ matrix.tag }} |
| 144 | + name: ${{ matrix.name }} |
| 145 | + registry: ${{ matrix.registry-uri }} |
| 146 | + username: AWS |
| 147 | + password: ${{ steps.get-ecr-token.outputs.aws-session-token }} |
| 148 | + decrypt-passphrase: ${{ secrets[matrix.pro-artifact-passphrase] }} |
| 149 | + |
| 150 | + - name: Upload Rock to Registry |
| 151 | + uses: canonical/oci-factory/.github/actions/upload-rock@main |
| 152 | + if: matrix.registry-auth-method == 'basic' |
| 153 | + with: |
| 154 | + artifact_name: ${{ matrix.artifact-name }} |
| 155 | + tags: ${{ matrix.tag }} |
| 156 | + name: ${{ matrix.name }} |
| 157 | + registry: ${{ matrix.registry-uri }} |
| 158 | + username: ${{ secrets[matrix.registry-auth-username] }} |
| 159 | + password: ${{ secrets[matrix.registry-auth-password] }} |
| 160 | + decrypt-passphrase: ${{ secrets[matrix.pro-artifact-passphrase] }} |
0 commit comments