|
| 1 | +name: upload to OCI |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + version: |
| 6 | + type: string |
| 7 | + default: today |
| 8 | +jobs: |
| 9 | + generate_matrix_publish: |
| 10 | + uses: ./.github/workflows/generate_matrix.yml |
| 11 | + with: |
| 12 | + flags: '--exclude "bare-*" --no-arch --json-by-arch --build --test' |
| 13 | + upload_gl_artifacts_to_oci: |
| 14 | + name: upload to OCI |
| 15 | + needs: [ generate_matrix_publish ] |
| 16 | + runs-on: ubuntu-latest |
| 17 | + defaults: |
| 18 | + run: |
| 19 | + shell: bash |
| 20 | + permissions: |
| 21 | + id-token: write |
| 22 | + packages: write |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: ${{ fromJson(needs.generate_matrix_publish.outputs.matrix) }} |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1 |
| 28 | + with: |
| 29 | + submodules: 'true' |
| 30 | + # bin/garden-version reads and writes from and to ./VERSION which is read by ./build --resolve-cname |
| 31 | + - name: set VERSION=${{ inputs.version }} |
| 32 | + run: | |
| 33 | + bin/garden-version "${{ inputs.version }}" | tee VERSION |
| 34 | + ls -la |
| 35 | + ver=$(cat VERSION) |
| 36 | + git update-index --assume-unchanged VERSION |
| 37 | + # TODO: fix the sed from below |
| 38 | + cname="$(./build --resolve-cname ${{ matrix.flavor }}-${{ matrix.arch }} | sed s/today/$ver/)" |
| 39 | + echo "cname=$cname" | tee -a "$GITHUB_ENV" |
| 40 | + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # pin@v4.1.8 |
| 41 | + with: |
| 42 | + name: build-${{ env.cname }} |
| 43 | + - name: Untar workflow artifact |
| 44 | + run: | |
| 45 | + mkdir ${{ env.cname }} |
| 46 | + tar -C ${{ env.cname }} -xzv < "${{ env.cname }}.tar.gz" |
| 47 | + - name: Set up Python 3.12 |
| 48 | + uses: actions/setup-python@v5 |
| 49 | + with: |
| 50 | + python-version: "3.12" |
| 51 | + - name: Install glcli util |
| 52 | + run: | |
| 53 | + git clone --depth 1 --branch 0.6.2 https://github.com/gardenlinux/python-gardenlinux-cli.git |
| 54 | + mv python-gardenlinux-cli /opt/glcli |
| 55 | + pip install -r /opt/glcli/requirements.txt |
| 56 | + - name: push using the glcli util |
| 57 | + run: | |
| 58 | + mkdir -p manifests |
| 59 | + GLOCI_REGISTRY_TOKEN=${{ secrets.GITHUB_TOKEN }} GLOCI_REGISTRY_USERNAME=${{ github.repository_owner }} python /opt/glcli/src/glcli.py push-manifest --dir ${{ env.cname }} --container ghcr.io/${{ github.repository }} --arch ${{ matrix.arch }} --version ${{ inputs.version }} --cname ${{ env.cname }} --cosign_file digest --manifest_file manifests/oci_manifest_entry_${{ env.cname }}.json |
| 60 | + - name: Upload oci manifest artifact |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: oci_manifest_entry_${{ env.cname }}.json |
| 64 | + path: manifests/ |
| 65 | + - name: Output digest to be signed |
| 66 | + run: | |
| 67 | + cat digest |
| 68 | + |
| 69 | + upload_manifests_entries: |
| 70 | + needs: "upload_gl_artifacts_to_oci" |
| 71 | + name: upload manifest entries into OCI index |
| 72 | + runs-on: ubuntu-latest |
| 73 | + defaults: |
| 74 | + run: |
| 75 | + shell: bash |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + packages: write |
| 79 | + actions: write |
| 80 | + steps: |
| 81 | + - name: Set up Python 3.12 |
| 82 | + uses: actions/setup-python@v5 |
| 83 | + with: |
| 84 | + python-version: "3.12" |
| 85 | + - name: Install glcli util |
| 86 | + run: | |
| 87 | + git clone --depth 1 --branch 0.6.2 https://github.com/gardenlinux/python-gardenlinux-cli.git |
| 88 | + mv python-gardenlinux-cli /opt/glcli |
| 89 | + pip install -r /opt/glcli/requirements.txt |
| 90 | + - name: Download OCI manifest artifacts |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + path: manifests |
| 94 | + pattern: oci_manifest_entry_* |
| 95 | + merge-multiple: true |
| 96 | + - name: Update index using glcli tool |
| 97 | + run: | |
| 98 | + GLOCI_REGISTRY_TOKEN=${{ secrets.GITHUB_TOKEN }} GLOCI_REGISTRY_USERNAME=${{ github.repository_owner }} python /opt/glcli/src/glcli.py update-index --container ghcr.io/${{ github.repository }} --version ${{ inputs.version }} --manifest_folder manifests |
| 99 | + - name: Delete temporary OCI manifest entry files |
| 100 | + uses: actions/github-script@v7 |
| 101 | + with: |
| 102 | + script: | |
| 103 | + const artifacts = await github.rest.actions.listArtifactsForRepo({ |
| 104 | + owner: context.repo.owner, |
| 105 | + repo: context.repo.repo, |
| 106 | + per_page: 100 |
| 107 | + }); |
| 108 | + for (const artifact of artifacts.data.artifacts) { |
| 109 | + if (artifact.name.startsWith('oci_manifest_entry_')) { |
| 110 | + console.log(`Deleting artifact: ${artifact.name}`); |
| 111 | + await github.rest.actions.deleteArtifact({ |
| 112 | + owner: context.repo.owner, |
| 113 | + repo: context.repo.repo, |
| 114 | + artifact_id: artifact.id |
| 115 | + }); |
| 116 | + console.log(`Successfully deleted artifact: ${artifact.name}`); |
| 117 | + } |
| 118 | + } |
0 commit comments