Skip to content

Merge pull request #91 from DarkFlorist/fix-small-screens #65

Merge pull request #91 from DarkFlorist/fix-small-screens

Merge pull request #91 from DarkFlorist/fix-small-screens #65

Workflow file for this run

name: Build and Push to IPFS
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Set IMAGE_TAG
run: echo "IMAGE_TAG=$(echo ${{ github.repository }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
- name: Build image
run: |
docker build . --file Dockerfile --tag $IMAGE_TAG
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
run: |
IMAGE_ID=ghcr.io/$IMAGE_TAG
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_TAG $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# Make image reference available to subsequent steps
echo "IMAGE_RELEASE_ID=$(echo $IMAGE_ID:$VERSION)" >> $GITHUB_ENV
# Run docker image script to publish app to nft.storage
- name: Publish to nft.storage
run: |
docker run -e NFTSTORAGE_API_KEY=${{ secrets.NFTSTORAGE_API_KEY }} $IMAGE_RELEASE_ID nft.storage
- name: Create a reference for IPFS hash
if: github.ref_type == 'tag'
run: |
echo "IPFS_HASH=$(docker run --entrypoint /bin/sh $IMAGE_RELEASE_ID -c 'cat /ipfs_hash.txt')" >> $GITHUB_ENV
- name: Create a release
if: github.ref_type == 'tag'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Markdown template for the release notes
RELEASE_NOTE_TEMPLATE=$(cat << EOF
#### IPFS Hash
\`\`\`
$IPFS_HASH
\`\`\`
You can view published versions of PetalLock through any IPFS Gateway
[ipfs://$IPFS_HASH](ipfs://$IPFS_HASH) __(Recommended)__
_requires Brave Browser or IPFS Desktop_
[https://$IPFS_HASH.ipfs.nftstorage.link](https://$IPFS_HASH.ipfs.nftstorage.link)
[https://$IPFS_HASH.ipfs.zoltu.io](https://$IPFS_HASH.ipfs.zoltu.io)
[https://$IPFS_HASH.ipfs.cf-ipfs.com](https://$IPFS_HASH.ipfs.cf-ipfs.com)
[https://$IPFS_HASH.ipfs.w3s.link](https://$IPFS_HASH.ipfs.w3s.link)
EOF
)
# Generate payload for creating a new release
PAYLOAD_TEMPLATE=$(cat <<EOF
{
"name": "$GITHUB_REF_NAME",
"tag_name": "$GITHUB_REF_NAME",
"body": $(echo "$RELEASE_NOTE_TEMPLATE" | jq -cRs '@json|fromjson'),
"draft": false,
"generate_release_notes": true
}
EOF
)
# Create a github release
# https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release
REQUEST_DATA=$(echo "$PAYLOAD_TEMPLATE" | jq -c)
RESPONSE=$(curl \
--silent \
--location \
--request POST \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--data "$REQUEST_DATA" \
--write-out "%{http_code}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases"
)
# Extract the response body and the appended http code
RESPONSE_CODE=${RESPONSE: -3}
RESPONSE_BODY=${RESPONSE//$RESPONSE_CODE/}
# Successful creation will return a status 201 (Created), otherwise show the error
if [ "$RESPONSE_CODE" -ne 201 ]; then
ERROR_MESSAGE=$(echo "$RESPONSE_BODY" | jq '.message')
echo "HTTP $RESPONSE_CODE - $ERROR_MESSAGE"
exit 1
fi
echo "Release ($GITHUB_REF_NAME) successfully created"