|
1 | | -name: Build release candidate |
| 1 | +name: Main CI |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: |
6 | | - - main |
| 5 | + branches: ['main'] |
| 6 | + pull_request: |
| 7 | + types: [opened, synchronize, reopened] |
7 | 8 |
|
8 | 9 | jobs: |
9 | | - check-version: |
| 10 | + build: |
10 | 11 | runs-on: ubuntu-latest |
11 | | - outputs: |
12 | | - release-version: ${{ steps.version.outputs.pe-version }} |
13 | | - tag-already-exists: ${{ steps.checkTag.outputs.exists }} |
| 12 | + if: github.event.head_commit.author.name != 'github-actions[bot]' |
14 | 13 | steps: |
15 | | - - name: Checkout |
16 | | - uses: actions/checkout@v3 |
17 | | - |
18 | | - - name: Get version |
19 | | - id: version |
20 | | - run: echo "pe-version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT |
21 | | - |
22 | | - - name: Print version |
23 | | - run: echo ${{ steps.version.outputs.pe-version }} |
24 | | - |
25 | | - - uses: mukunku/tag-exists-action@v1.2.0 |
26 | | - id: checkTag |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + - uses: actions/setup-node@v4 |
27 | 16 | with: |
28 | | - tag: ${{ steps.version.outputs.pe-version }} |
29 | | - |
30 | | - - if: ${{ steps.checkTag.outputs.exists == 'true' }} |
31 | | - name: "Skip release" |
32 | | - run: echo "Nothing to tag/release, the release ${{ steps.version.outputs.pe-version }} already exists" |
| 17 | + node-version: '20' |
| 18 | + - run: yarn && yarn build |
| 19 | + - uses: actions/upload-artifact@v4 |
| 20 | + with: |
| 21 | + name: public-enemy |
| 22 | + path: dist |
33 | 23 |
|
34 | | - create-release: |
35 | | - needs: check-version |
| 24 | + check_if_version_upgraded: |
| 25 | + needs: build |
36 | 26 | runs-on: ubuntu-latest |
37 | | - if: ${{ needs.check-version.outputs.tag-already-exists == 'false' }} |
| 27 | + if: | |
| 28 | + github.event_name == 'push' || |
| 29 | + github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login |
| 30 | + outputs: |
| 31 | + version: ${{ steps.version.outputs.prop }} |
| 32 | + is_version_changed: ${{ steps.check.outputs.exists == 'false' }} |
| 33 | + is_pre_release: ${{ contains(steps.version.outputs.prop, '-rc' ) }} |
38 | 34 | steps: |
39 | | - - uses: actions/checkout@v3 |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + - id: version |
| 37 | + uses: notiz-dev/github-action-json-property@release |
40 | 38 | with: |
41 | | - ref: ${{ github.ref }} |
42 | | - fetch-depth: 0 |
43 | | - |
44 | | - - name: Get previous tag |
45 | | - id: previousTag |
46 | | - run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+$' | tail -1)" >> $GITHUB_OUTPUT |
47 | | - |
48 | | - - name: Create release note |
49 | | - id: changelog |
50 | | - uses: requarks/changelog-action@v1 |
51 | | - with: |
52 | | - fromTag: ${{ github.sha }} |
53 | | - toTag: ${{ steps.previousTag.outputs.previousTag}} |
54 | | - token: ${{ secrets.GITHUB_TOKEN }} |
55 | | - writeToFile: false |
56 | | - |
57 | | - - uses: softprops/action-gh-release@v1 |
| 39 | + path: 'package.json' |
| 40 | + prop_path: 'version' |
| 41 | + ## we check if repo contains already this tag, if not version, has changed |
| 42 | + - uses: mukunku/tag-exists-action@v1.6.0 |
| 43 | + id: check |
58 | 44 | with: |
59 | | - tag_name: ${{ needs.check-version.outputs.release-version }} |
60 | | - target_commitish: ${{ github.head_ref || github.ref }} |
61 | | - name: ${{ needs.check-version.outputs.release-version }} |
62 | | - body: ${{steps.changelog.outputs.changes}} |
63 | | - env: |
64 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + tag: ${{ steps.version.outputs.prop }} |
65 | 46 |
|
66 | | - build-release: |
67 | | - needs: create-release |
| 47 | + docker_public_enemy: |
| 48 | + needs: check_if_version_upgraded |
| 49 | + if: | |
| 50 | + (github.event_name == 'push' || needs.check_if_version_upgraded.outputs.is_pre_release == 'true') && |
| 51 | + needs.check_if_version_upgraded.outputs.is_version_changed == 'true' |
68 | 52 | runs-on: ubuntu-latest |
69 | 53 | steps: |
70 | | - - name: Extract branch name |
71 | | - shell: bash |
72 | | - run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT |
73 | | - id: extract_branch |
74 | | - |
75 | | - - uses: actions/checkout@v3 |
76 | | - with: |
77 | | - ref: ${{ steps.extract_branch.outputs.branch }} |
78 | | - |
79 | | - - name: Use Node.js 18 |
80 | | - uses: actions/setup-node@v3 |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + - uses: docker/setup-qemu-action@v3 |
| 56 | + - uses: docker/setup-buildx-action@v3 |
| 57 | + - uses: docker/login-action@v3 |
81 | 58 | with: |
82 | | - node-version: 18 |
83 | | - - run: yarn |
84 | | - - run: yarn build |
85 | | - |
86 | | - - name: Upload build |
87 | | - uses: actions/upload-artifact@v3 |
| 59 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 60 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 61 | + - uses: actions/download-artifact@v4 |
88 | 62 | with: |
89 | | - name: build |
| 63 | + name: public-enemy |
90 | 64 | path: dist |
91 | | - docker: |
92 | | - needs: |
93 | | - - check-version |
94 | | - - build-release |
| 65 | + - uses: docker/build-push-action@v6 |
| 66 | + with: |
| 67 | + platforms: linux/amd64,linux/arm64 |
| 68 | + context: '.' |
| 69 | + push: true |
| 70 | + tags: | |
| 71 | + inseefr/public-enemy:latest, |
| 72 | + inseefr/public-enemy:${{ needs.check_if_version_upgraded.outputs.version }} |
| 73 | +
|
| 74 | + release: |
95 | 75 | runs-on: ubuntu-latest |
| 76 | + needs: check_if_version_upgraded |
| 77 | + # We create release only if the version in the package.json have been upgraded and this CI is running against the main branch. |
| 78 | + # We allow branches with a PR open on main to publish pre-release (x.y.z-rc.u) but not actual releases. |
| 79 | + if: | |
| 80 | + (github.event_name == 'push' || needs.check_if_version_upgraded.outputs.is_pre_release == 'true') && |
| 81 | + needs.check_if_version_upgraded.outputs.is_version_changed == 'true' |
96 | 82 | steps: |
97 | | - - uses: actions/checkout@v3 |
98 | | - |
99 | | - - name: Download build |
100 | | - id: download |
101 | | - uses: actions/download-artifact@v3 |
| 83 | + - uses: actions/checkout@v4 |
102 | 84 | with: |
103 | | - name: build |
| 85 | + ref: ${{ github.ref }} |
| 86 | + - uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + name: public-enemy |
104 | 89 | path: dist |
105 | | - |
106 | | - - name: Publish to Registry |
107 | | - uses: elgohr/Publish-Docker-Github-Action@v5 |
| 90 | + - name: Zip bundle |
| 91 | + run: cd dist && zip -r ../public-enemy.zip ./* |
| 92 | + - uses: softprops/action-gh-release@v2 |
108 | 93 | with: |
109 | | - name: inseefr/public-enemy |
110 | | - username: ${{ secrets.DOCKERHUB_USERNAME }} |
111 | | - password: ${{ secrets.DOCKERHUB_TOKEN }} |
112 | | - tags: "${{ needs.check-version.outputs.release-version }}" |
| 94 | + name: Release ${{ needs.check_if_version_upgraded.outputs.version }} |
| 95 | + tag_name: ${{ needs.check_if_version_upgraded.outputs.version }} |
| 96 | + target_commitish: ${{ github.head_ref || github.ref }} |
| 97 | + generate_release_notes: true |
| 98 | + draft: false |
| 99 | + prerelease: ${{ needs.check_if_version_upgraded.outputs.is_pre_release == 'true' }} |
| 100 | + files: ./public-enemy.zip |
| 101 | + env: |
| 102 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments