diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bb8b880..46e2cf4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,29 +9,47 @@ jobs: - name: Get sample .apk for test purposes run: wget https://github.com/appium/appium/raw/1.10/sample-code/apps/ApiDemos-debug.apk - name: Upload artifact to Firebase Distribution + id: testing_outputs uses: ./ with: appId: ${{secrets.FIREBASE_APP_ID}} - token: ${{secrets.FIREBASE_TOKEN}} groups: Testers file: ApiDemos-debug.apk + serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} + - name: Assert outputs of previous step are not empty + run: | + echo "${{ steps.testing_outputs.outputs.FIREBASE_CONSOLE_URI }}" + if [[ -z "${{ steps.testing_outputs.outputs.FIREBASE_CONSOLE_URI }}" ]]; then + echo "Console URI is empty" >&2 + exit 1 + fi + echo "${{ steps.testing_outputs.outputs.TESTING_URI }}" + if [[ -z "${{ steps.testing_outputs.outputs.TESTING_URI }}" ]]; then + echo "Testing URI is empty" >&2 + exit 1 + fi + echo "${{ steps.testing_outputs.outputs.BINARY_DOWNLOAD_URI }}" + if [[ -z "${{ steps.testing_outputs.outputs.BINARY_DOWNLOAD_URI }}" ]]; then + echo "Binary download URI is empty" >&2 + exit 1 + fi - name: Upload artifact to Firebase Distribution with release note file uses: ./ with: appId: ${{secrets.FIREBASE_APP_ID}} - token: ${{secrets.FIREBASE_TOKEN}} groups: Testers releaseNotesFile: README.md file: ApiDemos-debug.apk + serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} - name: Upload artifact to Firebase Distribution with debug uses: ./ with: appId: ${{secrets.FIREBASE_APP_ID}} - token: ${{secrets.FIREBASE_TOKEN}} groups: Testers releaseNotesFile: README.md file: ApiDemos-debug.apk debug: true + serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} - name: Fetch credential file from secrets id: fetch_credential_file uses: timheuer/base64-to-file@v1 @@ -62,8 +80,27 @@ jobs: uses: ./ with: appId: ${{secrets.FIREBASE_APP_ID}} - token: ${{secrets.FIREBASE_TOKEN}} testers: "test@test.com, test2@test2.com" releaseNotesFile: README.md file: ApiDemos-debug.apk + serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} + - name: Failure during upload should set failure in action step + id: fail_check + uses: ./ + continue-on-error: true + with: + appId: invalid_app_id + testers: "test@test.com, test2@test2.com" + releaseNotesFile: README.md + file: ApiDemos-debug.apk + serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }} + - name: Check if previous step failed as expected + run: | + if [[ "${{ steps.fail_check.outcome }}" == 'failure' ]]; then + echo "Previous step failed as expected" + exit 0 + else + echo "Previous step succeeded, when it shouldn't" + exit 1 + fi diff --git a/.github/workflows/publish_image.yml b/.github/workflows/publish_image.yml new file mode 100644 index 0000000..baafc73 --- /dev/null +++ b/.github/workflows/publish_image.yml @@ -0,0 +1,50 @@ +name: Create and publish a Docker image + +# Edited snippet from: https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + workflow_dispatch: + +# 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 + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v3 + # 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: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + # minimal (short sha) + type=sha + + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + diff --git a/Dockerfile b/Dockerfile index e1804ba..5773917 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine3.15 +FROM node:20-alpine WORKDIR /app COPY . /app diff --git a/README.md b/README.md index 7300c53..0cfdf21 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This action uploads artifacts (.apk,.aab or .ipa) to Firebase App Distribution. ### `appId` -**Required** App id can be found on the General Settings page +**Required** App id can be found in the Firebase console in your Projects Settings, under Your apps. It is in the following format 1:1234567890123942955466829:android:1234567890abc123abc123 ### `token` @@ -54,6 +54,20 @@ Specify the release note path to a plain text file. Flag that can be included to print verbose log output. Default value is `false` +## Outputs + +### `FIREBASE_CONSOLE_URI` + +Link to uploaded release in the Firebase console. + +### `TESTING_URI` + +Link to share release with testers who have access. + +### `BINARY_DOWNLOAD_URI` + +Link to download the release binary (link expires in 1 hour). + ## Sample usage ``` diff --git a/action.yml b/action.yml index e14ea81..06b44f2 100644 --- a/action.yml +++ b/action.yml @@ -38,4 +38,4 @@ branding: icon: 'send' runs: using: 'docker' - image: 'Dockerfile' + image: docker://ghcr.io/wzieba/firebase-distribution-github-action:sha-344aa66 diff --git a/entrypoint.sh b/entrypoint.sh index 64c416d..c842ef7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -o pipefail + # Required since https://github.blog/2022-04-12-git-security-vulnerability-announced git config --global --add safe.directory $GITHUB_WORKSPACE @@ -41,8 +43,20 @@ firebase \ --testers "$INPUT_TESTERS" \ ${RELEASE_NOTES:+ --release-notes "${RELEASE_NOTES}"} \ ${INPUT_RELEASENOTESFILE:+ --release-notes-file "${RELEASE_NOTES_FILE}"} \ - $( (( $INPUT_DEBUG )) && printf %s '--debug' ) - -if [ -n "${INPUT_TOKEN}" ] ; then - echo ${TOKEN_DEPRECATED_WARNING_MESSAGE} -fi \ No newline at end of file + $( (( $INPUT_DEBUG )) && printf %s '--debug' ) | +{ + while read -r line; do + echo $line + + if [[ $line == *"View this release in the Firebase console"* ]]; then + CONSOLE_URI=$(echo "$line" | sed -e 's/.*: //' -e 's/^ *//;s/ *$//') + echo "FIREBASE_CONSOLE_URI=$CONSOLE_URI" >>"$GITHUB_OUTPUT" + elif [[ $line == *"Share this release with testers who have access"* ]]; then + TESTING_URI=$(echo "$line" | sed -e 's/.*: //' -e 's/^ *//;s/ *$//') + echo "TESTING_URI=$TESTING_URI" >>"$GITHUB_OUTPUT" + elif [[ $line == *"Download the release binary"* ]]; then + BINARY_URI=$(echo "$line" | sed -e 's/.*: //' -e 's/^ *//;s/ *$//') + echo "BINARY_DOWNLOAD_URI=$BINARY_URI" >>"$GITHUB_OUTPUT" + fi + done +}