|
1 | 1 | name: Deployment |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: [main] |
6 | | - merge_group: |
7 | | - pull_request: |
8 | | - branches: [main] |
9 | | - # Allows you to run this workflow manually from the Actions tab |
10 | | - workflow_dispatch: |
11 | | - |
12 | | -# Automatically cancel in-progress actions on the same branch |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
13 | 8 | concurrency: |
14 | | - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} |
15 | | - cancel-in-progress: true |
| 9 | + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} |
| 10 | + cancel-in-progress: true |
16 | 11 |
|
17 | 12 | env: |
18 | | - REGISTRY: docker.io |
19 | | - IMAGE_NAME: trueberryless/truzzles |
20 | | - NODE_VERSION: 20 |
| 13 | + REGISTRY: docker.io |
| 14 | + IMAGE_OWNER: trueberryless |
| 15 | + IMAGE_NAME: truzzles |
| 16 | + NODE_VERSION: 20 |
21 | 17 |
|
22 | 18 | jobs: |
23 | | - deployment: |
24 | | - if: contains(github.event.head_commit.message, 'deploy') || github.event_name == 'workflow_dispatch' |
25 | | - runs-on: ubuntu-latest |
26 | | - permissions: |
27 | | - contents: write |
28 | | - steps: |
29 | | - - name: Check out the repo |
30 | | - uses: actions/checkout@v4 |
31 | | - with: |
32 | | - fetch-depth: 0 |
33 | | - |
34 | | - - name: Create tag |
35 | | - run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME-$GITHUB_SHA)" >> $GITHUB_ENV |
36 | | - |
37 | | - - name: Set up Docker Buildx |
38 | | - uses: docker/setup-buildx-action@v2 |
39 | | - |
40 | | - - name: Log in to Docker Hub |
41 | | - uses: docker/login-action@v2 |
42 | | - with: |
43 | | - username: ${{ secrets.DOCKER_USERNAME }} |
44 | | - password: ${{ secrets.DOCKER_PASSWORD }} |
45 | | - |
46 | | - - name: Extract metadata (tags, labels) for Docker |
47 | | - id: meta |
48 | | - uses: docker/metadata-action@v4 |
49 | | - with: |
50 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
51 | | - |
52 | | - - name: Build and push Docker image |
53 | | - uses: docker/build-push-action@v5 |
54 | | - with: |
55 | | - context: . |
56 | | - push: true |
57 | | - tags: | |
58 | | - ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} |
59 | | - ${{ env.IMAGE_NAME }}:latest |
60 | | - labels: ${{ steps.meta.outputs.labels }} |
61 | | - |
62 | | - - name: Update deployment.yaml file |
63 | | - run: | |
64 | | - yq eval '.spec.template.spec.containers[0].image = "${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}"' -i manifest/deployment.yaml |
65 | | -
|
66 | | - - uses: stefanzweifel/git-auto-commit-action@v4 |
67 | | - with: |
68 | | - commit_message: update deployment.json container image (automated) |
69 | | - |
70 | | - - uses: ncipollo/release-action@v1 |
71 | | - with: |
72 | | - tag: ${{ env.IMAGE_TAG }} |
73 | | - makeLatest: true |
74 | | - body: "A docker image has been deployed to [Docker Hub](https://hub.docker.com/r/${{ env.IMAGE_NAME }}/tags)." |
| 19 | + changesets: |
| 20 | + name: Changesets |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + hasChangesets: ${{ steps.changesets.outputs.hasChangesets }} |
| 24 | + permissions: |
| 25 | + contents: write |
| 26 | + pull-requests: write |
| 27 | + steps: |
| 28 | + - name: Generate GitHub App token |
| 29 | + id: generate_token |
| 30 | + uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 |
| 31 | + with: |
| 32 | + app_id: ${{ secrets.BOT_APP_ID }} |
| 33 | + private_key: ${{ secrets.BOT_PRIVATE_KEY }} |
| 34 | + |
| 35 | + - name: Checkout Repo |
| 36 | + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 |
| 37 | + |
| 38 | + - name: Setup PNPM |
| 39 | + uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 |
| 40 | + |
| 41 | + - name: Setup Node |
| 42 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 43 | + with: |
| 44 | + node-version: ${{ env.NODE_VERSION }} |
| 45 | + cache: "pnpm" |
| 46 | + |
| 47 | + - name: Install Dependencies |
| 48 | + run: pnpm i |
| 49 | + |
| 50 | + - name: Create Release Pull Request |
| 51 | + uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3 |
| 52 | + id: changesets |
| 53 | + with: |
| 54 | + version: pnpm run version |
| 55 | + commit: "ci: release" |
| 56 | + title: "ci: release [skip netlify]" |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token}} |
| 59 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 60 | + |
| 61 | + - name: Get published version |
| 62 | + if: steps.changesets.outputs.hasChangesets == 'true' |
| 63 | + run: | |
| 64 | + git checkout changeset-release/main |
| 65 | + VERSION=$(node -p "require('./<%= projectFolder %>/package.json').version") |
| 66 | + NAME=$(node -p "require('./<%= projectFolder %>/package.json').name") |
| 67 | + git commit --amend -m "ci: release $NAME v$VERSION" --no-edit |
| 68 | + git push origin changeset-release/main:changeset-release/main --force |
| 69 | +
|
| 70 | + image-tag: |
| 71 | + name: Image Tag |
| 72 | + runs-on: ubuntu-latest |
| 73 | + outputs: |
| 74 | + IMAGE_TAG: ${{ env.IMAGE_TAG }} |
| 75 | + steps: |
| 76 | + - name: Check out the repo |
| 77 | + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 |
| 78 | + |
| 79 | + - name: Read version from package.json |
| 80 | + id: get_version |
| 81 | + run: | |
| 82 | + VERSION=$(jq -r '.version' <%= projectFolder %>/package.json) |
| 83 | + echo "IMAGE_TAG=$VERSION" >> $GITHUB_ENV |
| 84 | +
|
| 85 | + deployment: |
| 86 | + needs: [changesets, image-tag] |
| 87 | + if: > |
| 88 | + ( |
| 89 | + needs.changesets.outputs.hasChangesets == 'false' && |
| 90 | + ( |
| 91 | + contains(github.event.head_commit.message, 'deploy') || |
| 92 | + contains(github.event.head_commit.message, 'release') |
| 93 | + ) |
| 94 | + ) || |
| 95 | + github.event_name == 'workflow_dispatch' |
| 96 | + runs-on: ubuntu-latest |
| 97 | + permissions: |
| 98 | + contents: write |
| 99 | + steps: |
| 100 | + - name: Check out the repo |
| 101 | + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 |
| 102 | + with: |
| 103 | + fetch-depth: 0 |
| 104 | + |
| 105 | + - name: Set up Docker Buildx |
| 106 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
| 107 | + |
| 108 | + - name: Log in to Docker Hub |
| 109 | + uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0 |
| 110 | + with: |
| 111 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 112 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 113 | + |
| 114 | + - name: Extract metadata (tags, labels) for Docker |
| 115 | + id: meta |
| 116 | + uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0 |
| 117 | + with: |
| 118 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }} |
| 119 | + |
| 120 | + - name: Build and push Docker image |
| 121 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
| 122 | + with: |
| 123 | + context: ./<%= projectFolder %> |
| 124 | + push: true |
| 125 | + tags: | |
| 126 | + ${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ needs.image-tag.outputs.IMAGE_TAG }} |
| 127 | + ${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:latest |
| 128 | + labels: ${{ steps.meta.outputs.labels }} |
| 129 | + |
| 130 | + - name: Update deployment.yaml file |
| 131 | + run: | |
| 132 | + yq eval '.spec.template.spec.containers[0].image = "${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ needs.image-tag.outputs.IMAGE_TAG }}"' -i manifest/deployment.yaml |
| 133 | +
|
| 134 | + - uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5.2.0 |
| 135 | + with: |
| 136 | + commit_message: update deployment.json container image (automated) |
| 137 | + |
| 138 | + release: |
| 139 | + name: Release |
| 140 | + needs: [image-tag, deployment] |
| 141 | + runs-on: ubuntu-latest |
| 142 | + permissions: |
| 143 | + contents: write |
| 144 | + steps: |
| 145 | + - name: Check out the repo |
| 146 | + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 |
| 147 | + |
| 148 | + - id: extract-changelog |
| 149 | + uses: sean0x42/markdown-extract@7b185cbe85263116bbf741e739e7198ba86465dc # v2.1.0 |
| 150 | + with: |
| 151 | + file: <%= projectFolder %>/CHANGELOG.md |
| 152 | + pattern: ${{ needs.image-tag.outputs.IMAGE_TAG }} |
| 153 | + |
| 154 | + - uses: ncipollo/release-action@v1 |
| 155 | + id: create_release |
| 156 | + with: |
| 157 | + tag: ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }} |
| 158 | + makeLatest: false |
| 159 | + body: ${{ steps.extract-changelog.outputs.markdown }} |
| 160 | + skipIfReleaseExists: true |
| 161 | + |
| 162 | + - name: Check if release was created |
| 163 | + id: check_release |
| 164 | + run: | |
| 165 | + if [ -z "${{ steps.create_release.outputs.html_url }}" ]; then |
| 166 | + echo "RELEASE_SKIPPED=true" >> $GITHUB_ENV |
| 167 | + else |
| 168 | + echo "RELEASE_SKIPPED=false" >> $GITHUB_ENV |
| 169 | + fi |
| 170 | +
|
| 171 | + - name: Discord notification |
| 172 | + if: env.RELEASE_SKIPPED == 'false' |
| 173 | + env: |
| 174 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 175 | + uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554 # 0.4.0 |
| 176 | + with: |
| 177 | + args: | |
| 178 | + # ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }} |
| 179 | +
|
| 180 | + ${{ steps.extract-changelog.outputs.markdown }} |
0 commit comments