Merge pull request #33 from bubblydoo/dependabot/npm_and_yarn/sharp-0… #110
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Layer ZIP | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Read version | |
id: package_lock_json | |
run: | | |
content=$(cat ./package-lock.json) | |
content="${content//'%'/'%25'}" | |
content="${content//$'\n'/'%0A'}" | |
content="${content//$'\r'/'%0D'}" | |
echo "::set-output name=packageLockJson::$content" | |
- name: Variables | |
id: vars | |
run: | | |
sharp_version="${{ fromJSON(steps.package_lock_json.outputs.packageLockJson).dependencies.sharp.version }}" | |
echo "::set-output name=sharp_version::$sharp_version" | |
release_exists="true" | |
git show-ref --tags --quiet --verify -- "refs/tags/$sharp_version" || release_exists="false" | |
echo "::set-output name=release_exists::$release_exists" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build | |
id: docker_build | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
tags: amazon-linux-sharp-layer:dev | |
# this action should be replaced with load: true in the docker_build action, see https://github.com/docker/buildx/issues/59 | |
- name: Load Docker images | |
run: | | |
docker buildx build --load --platform linux/amd64 -t amazon-linux-sharp-layer:dev-x86_64 . && | |
docker buildx build --load --platform linux/arm64 -t amazon-linux-sharp-layer:dev-aarch64 . | |
- name: Copy artifacts x86_64 | |
run: docker run --platform linux/amd64 -v "${{ github.workspace }}/dist":/dist amazon-linux-sharp-layer:dev-x86_64 | |
- name: Copy artifacts aarch64 | |
run: docker run --platform linux/arm64 -v "${{ github.workspace }}/dist":/dist amazon-linux-sharp-layer:dev-aarch64 | |
- name: Upload artifacts x86_64 | |
uses: actions/upload-artifact@v2 | |
with: | |
name: sharp-lambda-layer.x86_64.zip | |
path: dist/sharp-layer.x86_64.zip | |
if-no-files-found: error | |
- name: Upload artifacts aarch64 | |
uses: actions/upload-artifact@v2 | |
with: | |
name: sharp-lambda-layer.aarch64.zip | |
path: dist/sharp-layer.aarch64.zip | |
if-no-files-found: error | |
- name: Create release | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.vars.outputs.release_exists == 'false' }} | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.vars.outputs.sharp_version }} | |
release_name: Version ${{ steps.vars.outputs.sharp_version }} | |
prerelease: ${{ contains(steps.vars.outputs.sharp_version, '-') }} | |
- name: Upload release asset x86_64 | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.vars.outputs.release_exists == 'false' }} | |
id: upload_release_asset_x86_64 | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: dist/sharp-layer.x86_64.zip | |
asset_name: sharp-lambda-layer.x86_64.zip | |
asset_content_type: application/zip | |
- name: Upload release asset aarch64 | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.vars.outputs.release_exists == 'false' }} | |
id: upload_release_asset_aarch64 | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: dist/sharp-layer.aarch64.zip | |
asset_name: sharp-lambda-layer.aarch64.zip | |
asset_content_type: application/zip |