diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7eee09e..a5b1d0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,19 +4,23 @@ on: workflow_call: inputs: version: - required: false + description: Version to build + required: true type: string -jobs: +env: + JAVA_DISTRIBUTION: zulu + JAVA_VERSION: 21 - verification: - runs-on: ubuntu-20.04 +jobs: + test: + runs-on: [ ubuntu-latest ] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: - distribution: 'zulu' - java-version: 21 - cache: 'gradle' - - run: | - ./gradlew test \ No newline at end of file + cache: gradle + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + ref: ${{ inputs.version }} + - run: ./gradlew test \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..256dcc5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,48 @@ +name: Deploy + +on: + workflow_call: + inputs: + version: + description: Version to deploy + required: true + type: string + +env: + HEROKU_REGISTRY_TOKEN: ${{ secrets.HEROKU_REGISTRY_TOKEN }} + JAVA_DISTRIBUTION: zulu + JAVA_VERSION: 21 + +jobs: + deploy: + runs-on: [ ubuntu-latest ] + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + cache: gradle + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + ref: ${{ inputs.version }} + + - name: Login to Heroku Container Registry + uses: docker/login-action@v3 + with: + password: ${{ env.HEROKU_REGISTRY_TOKEN }} + registry: registry.heroku.com + username: _ + + - name: Push image to Heroku registry + run: ./gradlew dockerPushHerokuProduction + + - name: Trigger release + shell: bash + run: | + export IMAGE_ID=$(docker inspect registry.heroku.com/chucky/web --format={{.Id}}) + curl -X PATCH \ + https://api.heroku.com/apps/chucky/formation \ + -H 'Accept: application/vnd.heroku+json; version=3.docker-releases' \ + -H "Authorization: Bearer ${HEROKU_REGISTRY_TOKEN}" \ + -H 'Content-Type: application/json' \ + -d "{\"updates\":[{\"type\":\"web\",\"docker_image\":\"${IMAGE_ID}\"}]}" diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 0000000..ea1b1aa --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,18 @@ +name: Build and deploy + +on: + push: + branches: [ master ] + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + version: ${{ github.sha }} + + deploy: + needs: build + secrets: inherit + uses: ./.github/workflows/deploy.yml + with: + version: ${{ github.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 83716bc..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,55 +0,0 @@ -# GitHub Actions documentation -# => https://docs.github.com/en/actions -name: Release - -on: - push: - branches: - - master - -jobs: - - unit-test: - if: "!contains(github.event.head_commit.message, 'skip-ci')" - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 21 - cache: 'gradle' - - run: | - ./gradlew test - - release: - if: "!contains(github.event.head_commit.message, 'skip-ci')" - needs: [ unit-test ] - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 21 - cache: 'gradle' - - name: Login to Heroku Docker Registry - uses: docker/login-action@v1 - with: - password: ${{ secrets.HEROKU_REGISTRY_TOKEN }} - registry: registry.heroku.com - username: _ - - name: 'Push image to Heroku registry' - run: ./gradlew dockerPushHerokuProduction - - name: Trigger release - shell: bash - env: - HEROKU_REGISTRY_TOKEN: ${{ secrets.HEROKU_REGISTRY_TOKEN }} - run: | - export IMAGE_ID=$(docker inspect registry.heroku.com/chucky/web --format={{.Id}}) - curl -X PATCH \ - https://api.heroku.com/apps/chucky/formation \ - -H 'Accept: application/vnd.heroku+json; version=3.docker-releases' \ - -H "Authorization: Bearer ${HEROKU_REGISTRY_TOKEN}" \ - -H 'Content-Type: application/json' \ - -d "{\"updates\":[{\"type\":\"web\",\"docker_image\":\"${IMAGE_ID}\"}]}" diff --git a/README.md b/README.md index 2cbc001..7eaf563 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CHUCKNORRIS.IO [![CircleCI](https://circleci.com/gh/chucknorris-io/chuck-api.svg?style=svg)](https://circleci.com/gh/chucknorris-io/chuck-api) +# CHUCKNORRIS.IO [chucknorris.io](https://api.chucknorris.io) is a free JSON API for hand curated Chuck Norris facts.