|
| 1 | +name: build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - feature-375 |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - 'command-line-tools/**' |
| 10 | + - .github/** |
| 11 | + - docs/** |
| 12 | + - cwl-workflow/*.cwl |
| 13 | + - codemeta.json |
| 14 | + |
| 15 | +jobs: |
| 16 | + validate: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v2 |
| 20 | + - uses: actions/setup-python@v2 |
| 21 | + with: |
| 22 | + python-version: 3.x |
| 23 | + - run: pip install cwltool |
| 24 | + - run: cwltool --validate cwl-workflow/app-water-bodies-cloud-native.cwl |
| 25 | + - run: cwltool --validate cwl-workflow/app-water-body-cloud-native.cwl |
| 26 | + - run: cwltool --validate cwl-workflow/app-water-body.cwl |
| 27 | + |
| 28 | + version: |
| 29 | + needs: validate |
| 30 | + runs-on: ubuntu-latest |
| 31 | + outputs: |
| 32 | + app-version: ${{ steps.set-version.outputs.version }} |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v2 |
| 35 | + - run: echo "APP_VERSION=$(cat codemeta.json | jq -r .version )" >> $GITHUB_ENV |
| 36 | + - run: echo app version is $APP_VERSION |
| 37 | + - id: set-version |
| 38 | + run: echo "::set-output name=version::$APP_VERSION" |
| 39 | + |
| 40 | + container-build: |
| 41 | + needs: version |
| 42 | + runs-on: ubuntu-latest |
| 43 | + strategy: |
| 44 | + matrix: |
| 45 | + step: [crop, norm_diff, otsu, stac, stage] |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v2 |
| 48 | + - run: echo version ${{needs.version.outputs.app-version}} |
| 49 | + - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 50 | + - name: build & push image |
| 51 | + run: | |
| 52 | + IMAGE_ID=ghcr.io/eoap/advanced-tooling/${{ matrix.step }} |
| 53 | + docker build command-line-tools/${{ matrix.step }} --file command-line-tools/${{ matrix.step }}/Dockerfile --tag ${{ matrix.step }} |
| 54 | + docker tag ${{ matrix.step }} $IMAGE_ID:${{needs.version.outputs.app-version}} |
| 55 | + docker push $IMAGE_ID:${{needs.version.outputs.app-version}} |
| 56 | +
|
| 57 | + create-release: |
| 58 | + needs: |
| 59 | + - container-build |
| 60 | + - version |
| 61 | + runs-on: ubuntu-latest |
| 62 | + outputs: |
| 63 | + upload_url: ${{ steps.set-upload-url.outputs.upload_url }} |
| 64 | + steps: |
| 65 | + - name: release |
| 66 | + uses: actions/create-release@v1 |
| 67 | + id: create_release |
| 68 | + with: |
| 69 | + draft: false |
| 70 | + prerelease: false |
| 71 | + release_name: ${{needs.version.outputs.app-version}} |
| 72 | + tag_name: ${{needs.version.outputs.app-version}} |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ github.token }} |
| 75 | + - id: set-upload-url |
| 76 | + run: echo "::set-output name=upload_url::${{ steps.create_release.outputs.upload_url }}" |
| 77 | + |
| 78 | + publish-artifacts: |
| 79 | + needs: |
| 80 | + - create-release |
| 81 | + - version |
| 82 | + runs-on: ubuntu-latest |
| 83 | + strategy: |
| 84 | + matrix: |
| 85 | + step: ["app-water-bodies-cloud-native", "app-water-body-cloud-native", "app-water-body"] |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v2 |
| 88 | + - run: | |
| 89 | + for step in crop norm_diff otsu stac |
| 90 | + do |
| 91 | + tag="ghcr.io/eoap/advanced-tooling/${step}:${{needs.version.outputs.app-version}}" |
| 92 | + docker pull ${tag} |
| 93 | + shatag=$( docker inspect ${tag} | yq -r '.[0]["RepoDigests"][0]' ) |
| 94 | + for cwl in $(ls cwl-workflow/*.cwl) |
| 95 | + do |
| 96 | + s="${step}" t="${shatag}" yq -i eval '(.$graph[] | select (.id == env(s)) ).hints.DockerRequirement.dockerPull = env(t)' $cwl |
| 97 | + done |
| 98 | + done |
| 99 | + - run: | |
| 100 | + for cwl in $(ls cwl-workflow/*.cwl) |
| 101 | + do |
| 102 | + r=$( cat codemeta.json | jq -r ".codeRepository" ) yq -i eval '."s:codeRepository" = {"URL" : env(r)}' $cwl |
| 103 | + v="${{needs.version.outputs.app-version}}" yq -i eval '."s:softwareVersion" = env(v)' $cwl |
| 104 | + n=$(cat codemeta.json | jq -r '(.author[0].givenName + " " + .author[0].familyName)') \ |
| 105 | + e=$(cat codemeta.json | jq -r '.author[0].email') \ |
| 106 | + a=$(cat codemeta.json | jq -r '.author[0].affiliation["name"]') \ |
| 107 | + yq eval -i '."s:author" += [{"class": "s:Person", "s.name": env(n), "s.email": env(e), "s.affiliation": env(a)}]' $cwl |
| 108 | + done |
| 109 | + - name: Cleanup downloads folder |
| 110 | + run: rm -rf downloads/* |
| 111 | + - run: | |
| 112 | + mkdir downloads |
| 113 | + for cwl in "app-water-bodies-cloud-native" "app-water-body-cloud-native" "app-water-body" |
| 114 | + do |
| 115 | + cp cwl-workflow/${cwl}.cwl downloads/${cwl}.${{needs.version.outputs.app-version}}.cwl |
| 116 | + done |
| 117 | + - uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: application-package-${{matrix.step}} |
| 120 | + path: downloads |
| 121 | + overwrite: true |
| 122 | + - name: upload linux artifact 1 |
| 123 | + uses: actions/upload-release-asset@v1 |
| 124 | + env: |
| 125 | + GITHUB_TOKEN: ${{ github.token }} |
| 126 | + with: |
| 127 | + upload_url: ${{needs.create-release.outputs.upload_url}} |
| 128 | + asset_path: downloads/${{matrix.step}}.${{needs.version.outputs.app-version}}.cwl |
| 129 | + asset_name: ${{matrix.step}}.${{needs.version.outputs.app-version}}.cwl |
| 130 | + asset_content_type: text/yaml |
| 131 | + |
| 132 | + publish-oci-artifact: |
| 133 | + needs: |
| 134 | + - publish-artifacts |
| 135 | + - version |
| 136 | + runs-on: ubuntu-latest |
| 137 | + strategy: |
| 138 | + matrix: |
| 139 | + step: ["app-water-bodies-cloud-native", "app-water-body-cloud-native", "app-water-body"] |
| 140 | + steps: |
| 141 | + - uses: actions/checkout@v2 |
| 142 | + |
| 143 | + - name: Install oras and syft |
| 144 | + run: | |
| 145 | + ORAS_VERSION="1.2.2" |
| 146 | + curl -sL "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_linux_amd64.tar.gz" | tar -xz oras |
| 147 | + sudo mv oras /usr/local/bin/ |
| 148 | + SYFT_VERSION="1.27.1" |
| 149 | + curl -sL "https://github.com/anchore/syft/releases/latest/download/syft_${SYFT_VERSION}_linux_amd64.tar.gz" | tar -xz syft |
| 150 | + sudo mv syft /usr/local/bin/ |
| 151 | +
|
| 152 | + - name: Authenticate with GitHub Container Registry |
| 153 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin |
| 154 | + |
| 155 | + - name: Prepare directories |
| 156 | + run: mkdir -p sboms downloads |
| 157 | + |
| 158 | + - name: Set file variables |
| 159 | + run: | |
| 160 | + VERSION=${{ needs.version.outputs.app-version }} |
| 161 | + OWNER_REPO=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') |
| 162 | + echo "CWL_FILE=downloads/${{ matrix.step }}.${VERSION}.cwl" >> $GITHUB_ENV |
| 163 | + echo "IMAGE_REF=ghcr.io/${OWNER_REPO}/${{ matrix.step }}:${VERSION}" >> $GITHUB_ENV |
| 164 | +
|
| 165 | + - name: Push CWL OCI artifact |
| 166 | + run: | |
| 167 | + oras push "${{ env.IMAGE_REF }}" \ |
| 168 | + --artifact-type application/cwl \ |
| 169 | + "${{ env.CWL_FILE }}":application/cwl |
| 170 | +
|
| 171 | + - name: Extract dockerPull image refs and generate SBOMs |
| 172 | + run: | |
| 173 | + IMAGES=$(yq e ' |
| 174 | + .["$graph"][] |
| 175 | + | select(.class == "CommandLineTool") |
| 176 | + | (.hints.DockerRequirement.dockerPull // .requirements.DockerRequirement.dockerPull) |
| 177 | + ' "${{ env.CWL_FILE }}") |
| 178 | +
|
| 179 | + for image in $IMAGES; do |
| 180 | + safe_name=$(echo "$image" | tr '/@:' '___') |
| 181 | + sbom_file="sboms/$safe_name.sbom.spdx.json" |
| 182 | +
|
| 183 | + echo "Generating SBOM for $image → $sbom_file" |
| 184 | + syft "$image" -o spdx-json > "$sbom_file" |
| 185 | +
|
| 186 | + echo "Attaching SBOM to CWL artifact..." |
| 187 | + oras attach "${{ env.IMAGE_REF }}" \ |
| 188 | + --artifact-type application/spdx+json \ |
| 189 | + "$sbom_file" |
| 190 | + done |
| 191 | +
|
| 192 | + - name: Show attached SBOMs |
| 193 | + run: ls -lh sboms |
0 commit comments