|
11 | 11 | required: false |
12 | 12 | default: '30' |
13 | 13 | type: string |
| 14 | + enable_git_commit: |
| 15 | + description: 'Aktivera git commits av markdown-filer' |
| 16 | + required: false |
| 17 | + default: true |
| 18 | + type: boolean |
| 19 | + branch_name: |
| 20 | + description: 'Branch namn att använda (krävs om enable_git_commit är true)' |
| 21 | + required: false |
| 22 | + default: 'workflow-artifact-data' |
| 23 | + type: string |
14 | 24 |
|
15 | 25 | permissions: |
16 | 26 | contents: write |
@@ -38,29 +48,47 @@ jobs: |
38 | 48 |
|
39 | 49 | - name: Fetch JSON from beta.rkrattsbaser.gov.se |
40 | 50 | run: | |
41 | | - python downloaders/fetch_new_sfs_docs.py --days ${{ inputs.days || '1' }} --output sfs_json |
| 51 | + python downloaders/fetch_new_sfs_docs.py --days ${{ inputs.days || '1' }} --output data/sfs_json |
42 | 52 | env: |
43 | 53 | PYTHONPATH: ${{ github.workspace }} |
44 | 54 |
|
45 | 55 | - name: Process JSON files to Markdown files with Selex tags |
46 | 56 | run: | |
47 | | - python sfs_processor.py --input sfs_json --output output/md --formats md-markers |
| 57 | + python sfs_processor.py --input data/sfs_json --output data/md-markers --formats md-markers |
48 | 58 | env: |
49 | 59 | PYTHONPATH: ${{ github.workspace }} |
50 | 60 |
|
| 61 | + - name: Upload JSON source files to Cloudflare R2 for permanent storage |
| 62 | + run: | |
| 63 | + aws configure set aws_access_key_id ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} |
| 64 | + aws configure set aws_secret_access_key ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} |
| 65 | + aws configure set region us-east-1 |
| 66 | + aws configure set output json |
| 67 | +
|
| 68 | + # Upload all JSON files to R2 for backup |
| 69 | + aws s3 sync data/sfs_json/ s3://${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}/sfs_json/ \ |
| 70 | + --endpoint-url https://${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}.r2.cloudflarestorage.com \ |
| 71 | + --content-type "application/json" \ |
| 72 | + --exclude "*.md" \ |
| 73 | + --include "*.json" |
| 74 | + env: |
| 75 | + AWS_DEFAULT_REGION: us-east-1 |
| 76 | + |
51 | 77 | - name: Configure Git |
| 78 | + if: inputs.enable_git_commit != 'false' |
52 | 79 | run: | |
53 | 80 | git config --local user.email "action@github.com" |
54 | 81 | git config --local user.name "GitHub Action" |
55 | 82 |
|
56 | 83 | - name: Commit and push changes |
| 84 | + if: inputs.enable_git_commit != 'false' |
57 | 85 | id: commit_changes |
58 | 86 | run: | |
59 | 87 | # Get current branch |
60 | 88 | CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
61 | | - |
| 89 | +
|
62 | 90 | # Create a new branch for commits if we have changes |
63 | | - git add output/md/ sfs_json/ |
| 91 | + git add data/md-markers/ data/sfs_json/ |
64 | 92 | if git diff --staged --quiet; then |
65 | 93 | echo "Inga nya filer att committa" |
66 | 94 | echo "has_changes=false" >> $GITHUB_OUTPUT |
|
71 | 99 | |
72 | 100 | # Create and switch to the new branch |
73 | 101 | git checkout -b "$COMMIT_BRANCH" |
74 | | - |
75 | | - git commit -m "Automatisk uppdatering av SFS-författningar $(date +'%Y-%m-%d')" |
| 102 | +
|
| 103 | + # Commit with multi-line message |
| 104 | + git commit -m "Automatisk uppdatering av SFS-författningar $(date +'%Y-%m-%d')" \ |
| 105 | + -m "" \ |
| 106 | + -m "Inkluderar:" \ |
| 107 | + -m "- Käll-JSON (data/sfs_json/)" \ |
| 108 | + -m "- Markdown med selex-taggar (data/md-markers/)" \ |
| 109 | + -m "- Backup till Cloudflare R2" |
76 | 110 | echo "has_changes=true" >> $GITHUB_OUTPUT |
77 | 111 | echo "commit_branch=${COMMIT_BRANCH}" >> $GITHUB_OUTPUT |
78 | 112 | |
@@ -113,16 +147,24 @@ jobs: |
113 | 147 | fi |
114 | 148 |
|
115 | 149 | - name: Trigger HTML export workflow |
116 | | - if: steps.commit_changes.outputs.has_changes == 'true' && steps.commit_changes.outputs.push_success == 'true' |
| 150 | + if: (inputs.enable_git_commit != 'false' && steps.commit_changes.outputs.has_changes == 'true' && steps.commit_changes.outputs.push_success == 'true') || (inputs.enable_git_commit == 'false') |
117 | 151 | uses: actions/github-script@v6 |
118 | 152 | with: |
119 | 153 | github-token: ${{ secrets.GITHUB_TOKEN }} |
120 | 154 | script: | |
| 155 | + const enableGitCommit = '${{ inputs.enable_git_commit }}' !== 'false'; |
| 156 | + const sourceRef = enableGitCommit |
| 157 | + ? '${{ steps.commit_changes.outputs.commit_branch }}' |
| 158 | + : '${{ inputs.branch_name }}'; |
| 159 | +
|
121 | 160 | github.rest.actions.createWorkflowDispatch({ |
122 | 161 | owner: context.repo.owner, |
123 | 162 | repo: context.repo.repo, |
124 | 163 | workflow_id: 'html-export-workflow.yml', |
125 | | - ref: context.ref |
| 164 | + ref: sourceRef || context.ref, |
| 165 | + inputs: { |
| 166 | + source_ref: sourceRef || 'main' |
| 167 | + } |
126 | 168 | }) |
127 | 169 |
|
128 | 170 | - name: Report push failure |
|
0 commit comments