diff --git a/.github/workflows/official-pr.yml b/.github/workflows/official-pr.yml new file mode 100644 index 00000000..fe1279d2 --- /dev/null +++ b/.github/workflows/official-pr.yml @@ -0,0 +1,62 @@ +name: Create official images PR + +on: + pull_request_target: + types: + - closed + + paths: + - "**/Dockerfile" + - "**/architectures" + - "**/docker-entrypoint.sh" + - "generate-stackbrew-library.sh" + - "functions.sh" + +jobs: + pr: + runs-on: ubuntu-latest + if: github.repository_owner == 'nodejs' && github.event.pull_request.merged_by != '' + + steps: + - name: Checkout the docker-node repo + uses: actions/checkout@v2 + with: + path: docker-node + fetch-depth: 50 + + - name: Checkout the official-images repo + uses: actions/checkout@v2 + with: + path: official-images + repository: docker-library/official-images + + - name: Generate Stackbrew for diff + run: | + cd docker-node + ./generate-stackbrew-library.sh > ../official-images/library/node + + - name: Create PR in official-images + id: create-pr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GH_API_TOKEN }} + push-to-fork: nodejs-github-bot/official-images + path: official-images + branch: node + commit-message: "Node: ${{ github.event.pull_request.title }}" + title: "Node: ${{ github.event.pull_request.title }}" + body: | + Pull Request: ${{ github.event.pull_request.html_url }} + @LaurentGoderre @pesho @PeterDaveHello @SimenB @Starefossen + + - name: PR details + run: | + echo "Pull Request Number - ${{ steps.create-pr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.create-pr.outputs.pull-request-url }}" + + - name: Create PR comment + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + Created PR on the official-images repo (${{ steps.create-pr.outputs.pull-request-url }}). See https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what if you are wondering when it will be available on the Docker Hub. diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 69242a0f..00000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -# DO NOT MODIFY. THIS FILE IS AUTOGENERATED # - ---- - -dist: xenial - -language: minimal - -stages: - - name: Deploy - if: branch = master AND type IN (push) - -jobs: - include: - - stage: Deploy - before_script: - - | - if ! git diff --name-only "$TRAVIS_COMMIT_RANGE" -- | grep -Eq "Dockerfile$"; then - if git diff --name-only "$TRAVIS_COMMIT_RANGE" -- | grep -Eq "^generate-stackbrew-library.sh$"; then - if ! git diff "$TRAVIS_COMMIT_RANGE" -- generate-stackbrew-library.sh | grep -Eq '^[-+]array_[0-9]'; then - echo "Skip deployment as none of the Dockerfiles and version tag array in generate-stackbrew-library.sh has been changed." - exit - fi - else - echo "Skip deployment as none of the Dockerfiles and generate-stackbrew-library.sh has been changed." - exit - fi - fi - script: - - ./generate-stackbrew-pr.sh "$TRAVIS_COMMIT_RANGE" diff --git a/ACTIVE_MAINTAINERS b/ACTIVE_MAINTAINERS deleted file mode 100644 index 6425f28e..00000000 --- a/ACTIVE_MAINTAINERS +++ /dev/null @@ -1,5 +0,0 @@ -LaurentGoderre -pesho -PeterDaveHello -SimenB -Starefossen diff --git a/generate-stackbrew-pr.sh b/generate-stackbrew-pr.sh deleted file mode 100755 index ce13aa4c..00000000 --- a/generate-stackbrew-pr.sh +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env bash - -set -e -. functions.sh - -COMMIT_RANGE="${1}" -COMMIT_ID="$(git show -s --format="%H" "${COMMIT_RANGE}" | head -n 1)" - -if [ -n "$TRAVIS" ]; then - COMMIT_MESSAGE="${TRAVIS_COMMIT_MESSAGE}" - BRANCH_NAME="travis-${TRAVIS_BUILD_ID}" - GITHUB_USERNAME="${AUTOPR_GITHUB_USERNAME:-nodejs-github-bot}" -else - COMMIT_MESSAGE="$(git show -s --format=%B "${COMMIT_ID}")" - BRANCH_NAME="autopr-$(date +%s)" - if [[ "$(git remote get-url origin)" =~ github.com/([^/]*)/docker-node.git ]]; then - GITHUB_USERNAME="${BASH_REMATCH[1]}" - fi -fi - -if [[ "${COMMIT_MESSAGE}" =~ Merge\ pull\ request\ \#([0-9]*) ]]; then - - # This is a merge from a pull request - PR_NUMBER="${BASH_REMATCH[1]}" - COMMIT_MESSAGE="$(printf "%s" "${COMMIT_MESSAGE}" | tail -n 1)" -fi - -IMAGES_FILE="library/node" -REPO_NAME="official-images" -ORIGIN_SLUG="${GITHUB_USERNAME}/${REPO_NAME}" -UPSTREAM_SLUG="${AUTOPR_UPSTREAM:-docker-library}/${REPO_NAME}" -DOCKER_SLUG="${TRAVIS_REPO_SLUG:-nodejs/docker-node}" -gitpath="../${REPO_NAME}" - -function auth_header() { - echo "Authorization: token ${GITHUB_API_TOKEN}" -} - -function permission_check() { - if [ -z "${GITHUB_API_TOKEN}" ]; then - fatal "Environment variable \$GITHUB_API_TOKEN is missing or empty" - fi - - auth="$(curl -H "$(auth_header)" \ - -s \ - "https://api.github.com")" - - if [ "$(echo "${auth}" | jq -r .message)" = "Bad credentials" ]; then - fatal "Authentication Failed! Invalid \$GITHUB_API_TOKEN" - fi - - auth="$(curl -H "$(auth_header)" \ - -s \ - "https://api.github.com/repos/${ORIGIN_SLUG}/collaborators/${GITHUB_USERNAME}/permission")" - if [ "$(echo "${auth}" | jq -r .message)" != "null" ]; then - fatal "\$GITHUB_API_TOKEN can't push to https://github.com/${ORIGIN_SLUG}.git" - fi -} - -function setup_git_author() { - # Set Git User Info - GIT_AUTHOR_NAME="Node.js GitHub Bot" - GIT_AUTHOR_EMAIL="github-bot@iojs.org" - GIT_COMMITTER_NAME="Node.js GitHub Bot" - GIT_COMMITTER_EMAIL="github-bot@iojs.org" - - export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL -} - -function message() { - echo "Node: ${COMMIT_MESSAGE}" -} - -function pr_payload() { - local escaped_message - local body - local maintainers - - escaped_message="$(echo "${COMMIT_MESSAGE}" | head -n 1 | sed -E -e "s/\"/\\\\\"/g")" - - if [ -n "${PR_NUMBER}" ]; then - body="Pull Request: ${DOCKER_SLUG}#${PR_NUMBER}" - else - body="Commit: https://github.com/${DOCKER_SLUG}/compare/${COMMIT_RANGE}" - fi - - for maintainer in $(xargs < ACTIVE_MAINTAINERS); do - maintainers="$maintainers @$maintainer" - done - - printf "{ - \"title\": \"Node: %s\", - \"body\" : \"%s.
cc %s\", - \"head\" : \"%s\", - \"base\": \"master\" - }" "${escaped_message}" "${body}" "${maintainers}" "${GITHUB_USERNAME}:${BRANCH_NAME}" -} - -function comment_payload() { - local pr_url - pr_url="${1}" - echo "{ - \"body\": \"Created PR to the ${REPO_NAME} repo (${pr_url}). See https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what if you are wondering when it will be available on the Docker Hub.\" - }" -} - -if images_updated "${COMMIT_RANGE}"; then - - permission_check - - # Set Git User Info - [ -z "$GIT_AUTHOR_NAME" ] && setup_git_author - - info "Cloning..." - git clone --depth 50 "https://github.com/${UPSTREAM_SLUG}.git" ${gitpath} 2> /dev/null - - stackbrew="$(./generate-stackbrew-library.sh)" - - cd ${gitpath} - - echo "${stackbrew}" > "${IMAGES_FILE}" - git checkout -b "${BRANCH_NAME}" - git add "${IMAGES_FILE}" - git commit -m "$(message)" - - info "Pushing..." - git fetch --unshallow "https://github.com/${ORIGIN_SLUG}.git" - git push "https://${GITHUB_API_TOKEN}:x-oauth-basic@github.com/${ORIGIN_SLUG}.git" -f "${BRANCH_NAME}" || fatal "Error pushing the updated stackbrew" - - cd - && rm -rf ${gitpath} - - info "Creating Pull request" - pr_response_payload="$(curl -H "$(auth_header)" \ - -s \ - -X POST \ - -d "$(pr_payload)" \ - "https://api.github.com/repos/${UPSTREAM_SLUG}/pulls")" - - url="$(echo "${pr_response_payload}" | jq -r .html_url)" - if [ "${url}" != "null" ]; then - info "Pull request created at ${url}" - - if [ -n "${PR_NUMBER}" ]; then - comment_endpoint="https://api.github.com/repos/${DOCKER_SLUG}/issues/${PR_NUMBER}/comments" - else - comment_endpoint="https://api.github.com/repos/${DOCKER_SLUG}/commits/${COMMIT_ID}/comments" - fi - - info "Creating Commit Comment" - commit_response_payload="$(curl -H "$(auth_header)" \ - -s \ - -X POST \ - -d "$(comment_payload "${url}")" \ - "${comment_endpoint}")" - - if [ "$(echo "${commit_response_payload}" | jq -r .message)" != "null" ]; then - fatal "Error linking the pull request (${error_message})" - else - comment_url="$(echo "${commit_response_payload}" | jq -r .html_url)" - info "Created comment at ${comment_url}" - fi - else - error_message=$(echo "${pr_response_payload}" | jq -r .message) - fatal "Error creating pull request (${error_message})" - fi -else - info "No change!" -fi diff --git a/travis.yml.template b/travis.yml.template deleted file mode 100644 index 346b2b81..00000000 --- a/travis.yml.template +++ /dev/null @@ -1,37 +0,0 @@ ---- - -dist: xenial - -language: minimal - -stages: - - Test - - name: Deploy - if: branch = master AND type IN (push) - -jobs: - fast_finish: true - - include: - - stage: Test - name: .travis.yml and travis.yml.template consistency - script: - - ./update.sh -t - - git diff --stat --exit-code .travis.yml - - - stage: Deploy - before_script: - - | - if ! git diff --name-only "$TRAVIS_COMMIT_RANGE" -- | grep -Eq "Dockerfile$"; then - if git diff --name-only "$TRAVIS_COMMIT_RANGE" -- | grep -Eq "^generate-stackbrew-library.sh$"; then - if ! git diff "$TRAVIS_COMMIT_RANGE" -- generate-stackbrew-library.sh | grep -Eq '^[-+]array_[0-9]'; then - echo "Skip deployment as none of the Dockerfiles and version tag array in generate-stackbrew-library.sh has been changed." - exit - fi - else - echo "Skip deployment as none of the Dockerfiles and generate-stackbrew-library.sh has been changed." - exit - fi - fi - script: - - ./generate-stackbrew-pr.sh "$TRAVIS_COMMIT_RANGE"