|
| 1 | +--- |
| 2 | + |
| 3 | +# ------------------------------------------------------------------------------------------------- |
| 4 | +# Job Name |
| 5 | +# ------------------------------------------------------------------------------------------------- |
| 6 | +name: nightly |
| 7 | + |
| 8 | + |
| 9 | +# ------------------------------------------------------------------------------------------------- |
| 10 | +# When to run |
| 11 | +# ------------------------------------------------------------------------------------------------- |
| 12 | +on: |
| 13 | + # Runs daily |
| 14 | + schedule: |
| 15 | + - cron: '0 0 * * *' |
| 16 | + |
| 17 | + |
| 18 | +# ------------------------------------------------------------------------------------------------- |
| 19 | +# What to run |
| 20 | +# ------------------------------------------------------------------------------------------------- |
| 21 | +jobs: |
| 22 | + nightly: |
| 23 | + name: "[ HTTPD ] (ref: ${{ matrix.refs }})" |
| 24 | + runs-on: ubuntu-latest |
| 25 | + strategy: |
| 26 | + fail-fast: False |
| 27 | + matrix: |
| 28 | + refs: |
| 29 | + - 'master' |
| 30 | + - '0.36' |
| 31 | + steps: |
| 32 | + |
| 33 | + # ------------------------------------------------------------ |
| 34 | + # Setup repository |
| 35 | + # ------------------------------------------------------------ |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v2 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + ref: ${{ matrix.refs }} |
| 41 | + |
| 42 | + - name: Set variables |
| 43 | + id: vars |
| 44 | + run: | |
| 45 | +
|
| 46 | + # Retrieve git info (tags, etc) |
| 47 | + git fetch --all |
| 48 | +
|
| 49 | + # Branch, Tag or Commit |
| 50 | + GIT_TYPE="$( \ |
| 51 | + curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ |
| 52 | + | sh \ |
| 53 | + | grep '^GIT_TYPE' \ |
| 54 | + | sed 's|.*=||g' \ |
| 55 | + )" |
| 56 | + # Branch name, Tag name or Commit Hash |
| 57 | + GIT_SLUG="$( \ |
| 58 | + curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ |
| 59 | + | sh \ |
| 60 | + | grep '^GIT_NAME' \ |
| 61 | + | sed 's|.*=||g' \ |
| 62 | + )" |
| 63 | + # Docker Tag |
| 64 | + if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then |
| 65 | + DOCKER_TAG="latest" |
| 66 | + else |
| 67 | + DOCKER_TAG="${GIT_SLUG}" |
| 68 | + fi |
| 69 | +
|
| 70 | + # Output |
| 71 | + echo "GIT_TYPE=${GIT_TYPE}" |
| 72 | + echo "GIT_SLUG=${GIT_SLUG}" |
| 73 | + echo "DOCKER_TAG=${DOCKER_TAG}" |
| 74 | +
|
| 75 | + # Export variable |
| 76 | + # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files |
| 77 | + echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} |
| 78 | + echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} |
| 79 | + echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} |
| 80 | +
|
| 81 | +
|
| 82 | + # ------------------------------------------------------------ |
| 83 | + # Build |
| 84 | + # ------------------------------------------------------------ |
| 85 | + - name: Build |
| 86 | + run: | |
| 87 | + retry() { |
| 88 | + for n in $(seq ${RETRIES}); do |
| 89 | + echo "[${n}/${RETRIES}] ${*}"; |
| 90 | + if eval "${*}"; then |
| 91 | + echo "[SUCC] ${n}/${RETRIES}"; |
| 92 | + return 0; |
| 93 | + fi; |
| 94 | + sleep ${PAUSE}; |
| 95 | + echo "[FAIL] ${n}/${RETRIES}"; |
| 96 | + done; |
| 97 | + return 1; |
| 98 | + } |
| 99 | + retry make build |
| 100 | + env: |
| 101 | + RETRIES: 20 |
| 102 | + PAUSE: 10 |
| 103 | + |
| 104 | + # ------------------------------------------------------------ |
| 105 | + # Test |
| 106 | + # ------------------------------------------------------------ |
| 107 | + - name: Test Docker Image |
| 108 | + run: | |
| 109 | + retry() { |
| 110 | + for n in $(seq ${RETRIES}); do |
| 111 | + echo "[${n}/${RETRIES}] ${*}"; |
| 112 | + if eval "${*}"; then |
| 113 | + echo "[SUCC] ${n}/${RETRIES}"; |
| 114 | + return 0; |
| 115 | + fi; |
| 116 | + sleep ${PAUSE}; |
| 117 | + echo "[FAIL] ${n}/${RETRIES}"; |
| 118 | + done; |
| 119 | + return 1; |
| 120 | + } |
| 121 | + retry make test |
| 122 | + env: |
| 123 | + RETRIES: 20 |
| 124 | + PAUSE: 10 |
| 125 | + |
| 126 | + |
| 127 | + # ------------------------------------------------------------ |
| 128 | + # Deploy |
| 129 | + # ------------------------------------------------------------ |
| 130 | + - name: Publish images (only repo owner) |
| 131 | + run: | |
| 132 | + retry() { |
| 133 | + for n in $(seq ${RETRIES}); do |
| 134 | + echo "[${n}/${RETRIES}] ${*}"; |
| 135 | + if eval "${*}"; then |
| 136 | + echo "[SUCC] ${n}/${RETRIES}"; |
| 137 | + return 0; |
| 138 | + fi; |
| 139 | + sleep ${PAUSE}; |
| 140 | + echo "[FAIL] ${n}/${RETRIES}"; |
| 141 | + done; |
| 142 | + return 1; |
| 143 | + } |
| 144 | +
|
| 145 | + # Output |
| 146 | + echo "GIT_TYPE=${GIT_TYPE}" |
| 147 | + echo "GIT_SLUG=${GIT_SLUG}" |
| 148 | + echo "DOCKER_TAG=${DOCKER_TAG}" |
| 149 | +
|
| 150 | + # Tag image |
| 151 | + retry make tag TAG=${DOCKER_TAG} |
| 152 | + docker images |
| 153 | +
|
| 154 | + # Login and Push |
| 155 | + retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} |
| 156 | + retry make push TAG=${DOCKER_TAG} |
| 157 | +
|
| 158 | + env: |
| 159 | + RETRIES: 20 |
| 160 | + PAUSE: 10 |
| 161 | + # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions |
| 162 | + if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id |
| 163 | + && ( |
| 164 | + (github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) |
| 165 | + || |
| 166 | + (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) |
| 167 | + || |
| 168 | + (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-')) |
| 169 | + ) |
0 commit comments